Class: Fulfil::Base
- Inherits:
-
Object
- Object
- Fulfil::Base
- Defined in:
- lib/fulfil/base.rb
Direct Known Subclasses
Class Method Summary collapse
-
.all(page = 1, per_page = 10) ⇒ Object
Method to get all objects in a model.
-
.find(filter = [], page = 1, per_page = 10) ⇒ Object
Method to find specific object in a model using filters.
-
.get(id) ⇒ Object
Method to get single object using ID.
Instance Method Summary collapse
-
#initialize(args) ⇒ Base
constructor
A new instance of Base.
-
#method_missing(method) ⇒ Object
This will return arguments as object methods.
Constructor Details
#initialize(args) ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/fulfil/base.rb', line 8 def initialize(args) @args = args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
This will return arguments as object methods.
38 39 40 41 42 |
# File 'lib/fulfil/base.rb', line 38 def method_missing(method) method = method.to_s raise NoMethodError, "No such method: #{method}" unless @args.keys.include? method @args[method] end |
Class Method Details
.all(page = 1, per_page = 10) ⇒ Object
Method to get all objects in a model
20 21 22 |
# File 'lib/fulfil/base.rb', line 20 def all(page=1,per_page=10) request.all({:page => page, :per_page => per_page}) end |
.find(filter = [], page = 1, per_page = 10) ⇒ Object
Method to find specific object in a model using filters
25 26 27 28 |
# File 'lib/fulfil/base.rb', line 25 def find(filter=[],page=1,per_page=10) raise ArgumentError, 'Please provide a filter' if filter.empty? request.find({:filter => filter, :page => page, :per_page => per_page}) end |
.get(id) ⇒ Object
Method to get single object using ID
14 15 16 17 |
# File 'lib/fulfil/base.rb', line 14 def get(id) raise ArgumentError, 'Please provide an ID' if id.to_s.empty? request.get id end |