Class: Fulfil::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fulfil/base.rb

Direct Known Subclasses

Product

Class Method Summary collapse

Instance Method Summary collapse

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.

Raises:

  • (NoMethodError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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