0.02
No release in over 3 years
Low commit activity in last 3 years
LogicalModel allows to use a resource as a model. It is based on web presentation http://www.slideshare.net/ihower/serviceoriented-design-and-implement-with-rails3
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.2.2
~> 1.6.4
>= 0
>= 0
~> 1.2.6

Runtime

>= 0.8.0
~> 1.2.1
>= 1.0.1
 Project Readme

<img src=“https://badge.fury.io/rb/logical_model.png” alt=“Gem Version” /> <img src=“https://travis-ci.org/dwaynemac/logical_model.png” /> <img src=“https://codeclimate.com/github/dwaynemac/logical_model.png” />

logical_model¶ ↑

LogicalModel allows to use a RESTfull resources as models.

It was written following this tutorial: www.slideshare.net/ihower/serviceoriented-design-and-implement-with-rails3

Assumptions¶ ↑

OUTDATED – some of this assumpitions are now configurable. Will update this readme as soon as possible.

LogicalModel makes some assumptions about the service you’ll be consuming

  • resource service is RESTfull

  • INDEX response is

    {
      collection: [resources...],
      total:      total items
    }
  • SHOW response is

    {
      .... resource attributes ...
    }
  • CREATE response on success is

    {
      id: created_id
    }
    
  • CREATE response on failure is

    {
      message: 'error message',
      error_codes: [],
      errors: attribute_errors
    }
    
  • UPDATE response on success is

    "OK"
    
  • UPDATE response on failure is

    {
      message: 'error message',
      error_codes: [],
      errors: attribute_errors
    }
    
  • DESTROY response is

    "ok"
    

Usage¶ ↑

In your Gemfile:

gem "logical_model"

In a model file:

class RemoteResource < LogicalModel

  set_resource_host "remote.server"
  set_resource_path "/api/remote/path"
  # equivalent: set_resource_url "remote.server", "/api/remote/path"

  # optional
  set_api_key(:token, 'asdfasdf') # will add token=asdfasdf to all requests.

  attribute :id
  attribute :attribute_a
  attribute :attribute_b

  validates_presence_of :id
end

Testing¶ ↑

To run spec:

bundle exec rake

Contributing to logical_model¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011,2012,2013 Dwayne Macgowan. See LICENSE.txt for further details.

TODO¶ ↑

  • put log in /log

  • on create parse response and show errors, etc.