Project

amos

0.0
No commit activity in last 3 years
No release in over 3 years
A simple server that determines the model and action data based upon the incoming url.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Amos - A Model Only Server.¶ ↑

AMOS is a rails plugin that provides a simple server that uses the url to decide which model to deliver. It is intended for front-end applications that use something like javascriptMVC.

E.g. If the incoming request is /recipe it executes the index action which does a find(:all) on the Recipe model.

Supported actions¶ ↑

:get => "/user" returns array of all users

:get => "/user?fields[only]=name" returns only the name attribute

:get => "/user?name=J%20Smith" returns all records with a name of J Smith

:get => "/user?name=J%20Smith&email=smith@smith.com" returns all records with a name of J Smith and an email of smith@smith.com

:get => "/users/1" returns record for user 1

:get => "/users/1?fields[only]=name" returns only the name attribute for user 1

:get => "/users/1?fields[include]=posts" returns the record for user plus any posts

:delete => "/users/1" deletes record 1 from users, returns success => true / false

:put => "/users/1" + form data. Updates user record 1.  Returns success => true / false

:post => "/users" + form data.  Create a new record, returns details of new record on success, or errors array on failure

*Amos gem is now available on rubygems.org*

Distributed under the MIT License, all rights reserved 2011 Geoff Drake

Source¶ ↑

The source is available on GitHub github.com/geoffd123/amos

Installation¶ ↑

Create a rails application as normal using:

rails create MyApp

Add the following line to your Gemfile

gem 'amos'

Run

bundle install

Amos uses cancan for its security checking so you need to add the following class in app/models/ability.rb

class Ability
  include CanCan::Ability

  def initialize(user)
    can :manage, :all
  end
end

Replace the code inside the initialize with your requirements. There is a skeleton class in lib/app/models/ability.rb that disallows any access, so if you are getting authorisation errors you have not overridden that version correctly.

Cancan also needs access to a method called current_user in the controllers. If you are using devise or similar this should automatically be available.

If not you will need to define the following in your ApplicationController class:

class ApplicationController < ActionController::Base
  def current_user
    nil
  end
end

If you are using user authentication replace the nil return with the current user record.

Finally create some models that match the code you have on the front-end.

rails g model recipes name:string description:string

And start the server

rails s

Your models should now be available on /recipe etc.

Take a look at spec/controllers/amos_controller_spec.rb and test/dummy/features/amos.feature for some examples of accessing the data and what is returned.

If you want to use pagination add limit=n and offset=n to your query url

:get => "/user?limit=10&offset=20" returns an array of the next 10 users starting at record 20

Things to to¶ ↑

  • More tests against a javascriptMVC application

Change list¶ ↑

Edge¶ ↑

Merged Nico’s changes to make returned data more jsmvc compliant and the accessing more active record friendly. Thanks Nico.

Updated specs and cukes to test the above changes.

Updated README to conform to above changes.

Removed will_paginate gem as pagination is now controlled from the client.

0.0.4¶ ↑

Added test and spec files to gemspec

Added functionality to allow use of rails dynamic finders

Added ability to paginate index and dynamic finder results

0.0.3¶ ↑

Fixed problem with incomplete file list in gemspec.

Fixed problem with cancan methods not being found when using gem in a rails app.

0.0.2¶ ↑

Implemented fields filters, associations.

Changed js errors to return correct status codes

Implemented pluggable security using CanCan

0.0.1¶ ↑

Basic skeleton and minimal functionality