Class: Boxxspring::Operation
- Inherits:
-
Object
- Object
- Boxxspring::Operation
- Defined in:
- lib/boxxspring/operation.rb
Instance Method Summary collapse
- #include(*arguments) ⇒ Object
-
#initialize(path, parameters = {}, result = Array) ⇒ Operation
constructor
A new instance of Operation.
- #limit(_limit) ⇒ Object
- #offset(_offset) ⇒ Object
- #order(by, direction = 'desc') ⇒ Object
- #query ⇒ Object
- #read ⇒ Object
- #where(parameters) ⇒ Object
- #write(node, objects) ⇒ Object
Constructor Details
#initialize(path, parameters = {}, result = Array) ⇒ Operation
Returns a new instance of Operation.
5 6 7 8 |
# File 'lib/boxxspring/operation.rb', line 5 def initialize( path, parameters = {}, result = Array ) @path = path @parameters = ( parameters || {} ).deep_dup end |
Instance Method Details
#include(*arguments) ⇒ Object
26 27 28 |
# File 'lib/boxxspring/operation.rb', line 26 def include( *arguments ) self.spawn( :include => self.normalize_include( *arguments ) ) end |
#limit(_limit) ⇒ Object
18 19 20 |
# File 'lib/boxxspring/operation.rb', line 18 def limit( _limit ) self.spawn( count: _limit ) end |
#offset(_offset) ⇒ Object
22 23 24 |
# File 'lib/boxxspring/operation.rb', line 22 def offset( _offset ) self.spawn( offset: _offset ) end |
#order(by, direction = 'desc') ⇒ Object
14 15 16 |
# File 'lib/boxxspring/operation.rb', line 14 def order( by, direction = 'desc' ) self.spawn( sort_by: by, sort_direction: direction ) end |
#query ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/boxxspring/operation.rb', line 30 def query result = nil Boxxspring::Request.new.tap do | request | request.get( @path, @parameters ).tap do | response | result = response.resources result = result.first if result.length > 0 && @result == Object end end result end |
#read ⇒ Object
41 42 43 44 45 |
# File 'lib/boxxspring/operation.rb', line 41 def read result = self.query result = result.first if result.present? && result.is_a?( Enumerable ) result end |
#where(parameters) ⇒ Object
10 11 12 |
# File 'lib/boxxspring/operation.rb', line 10 def where( parameters ) self.spawn( parameters ) end |
#write(node, objects) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/boxxspring/operation.rb', line 47 def write( node, objects ) result = nil Boxxspring::Request.new.tap do | request | serializer = Boxxspring::Serializer.new( objects ) response = request.post( @path, @parameters, serializer.serialize( node ) ) if response.present? result = response.resources end end result end |