boxxspring 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3bda46388aec2e118b9457c34612d524e1122f6
4
- data.tar.gz: 7143fa88120d3b42f789d80c05507caa94bd05e2
3
+ metadata.gz: 826b0ca29329611f42824b85fc17b41e6a9c0771
4
+ data.tar.gz: 916bf662821ff5072ac0a954a1a4a0f4b93c26ed
5
5
  SHA512:
6
- metadata.gz: afd5f2eb665a1740cb5e6e774f582557e0b46985ef7945f90207364ff3619b8cd055f8ab7b72302d3943fd88ff9f5d7089b0b930490b26bf2de3babe44d5f758
7
- data.tar.gz: b7869533d1c3275dd6984e868618c7d9bdbeb72c8884af4915b47e23f28123da0fa8a46d80624fb69bb06c612b2ad174f208c33500aca2a1b7dfefbc8ce3a07d
6
+ metadata.gz: cbd26015df121dffded725d3135774879a22ae93c4a83d64e6c7d03542fe47d25fe1278180e283f9a0bae02ed01a5206de246e0235e0959d81d4db44473c5145
7
+ data.tar.gz: 1c80c90180d2d5ee07fa8b4b9297172b3cc6fd95f8234279807c1d6de6b7249d1a9ee7f724dea4740182462627558ba75c9941bd4914f3c498a8d8cfa532980f
@@ -2,22 +2,44 @@ module Boxxspring
2
2
 
3
3
  class Operation
4
4
 
5
- def initialize( path )
5
+ def initialize( path, parameters = {}, result = Array )
6
6
  @path = path
7
- @parameters = {}
7
+ @parameters = ( parameters || {} ).deep_dup
8
+ end
9
+
10
+ def where( parameters )
11
+ self.spawn( parameters )
12
+ end
13
+
14
+ def order( by, direction = 'desc' )
15
+ self.spawn( sort_by: by, sort_direction: direction )
8
16
  end
9
17
 
10
18
  def query
11
19
  result = nil
12
20
  Boxxspring::Request.new.tap do | request |
13
- request.get( @path ).tap do | response |
21
+ request.get( @path, @parameters ).tap do | response |
14
22
  parser = Boxxspring::Parser.new( response.content )
15
23
  result = parser.resources
24
+ result = result.first if result.length > 0 && @result == Object
16
25
  end
17
26
  end
18
27
  result
19
28
  end
20
29
 
30
+ def read
31
+ result = self.query
32
+ result = result.first if result.present? && result.is_a?( Enumerable )
33
+ result
34
+ end
35
+
36
+ protected; def spawn( parameters )
37
+ Boxxspring::Operation.new(
38
+ @path,
39
+ @parameters.deep_merge( parameters || {} )
40
+ )
41
+ end
42
+
21
43
  end
22
44
 
23
- end
45
+ end
@@ -24,13 +24,13 @@ module Boxxspring
24
24
  def self.has_one( name, options = {} )
25
25
  define_method name do
26
26
  associations = self.instance_variable_get( "@_#{name.to_s.pluralize}" )
27
- associations.present? ? associations.first : options[ :default]
27
+ associations.present? ? associations.first : options[ :default ]
28
28
  end
29
29
  end
30
30
 
31
31
  def self.has_many( name, options = {} )
32
32
  define_method name do
33
- self.instance_variable_get( "@_#{name}" ) || options[ :default ]
33
+ self.instance_variable_get( "@_#{name}" ) || options[ :default ] || []
34
34
  end
35
35
  end
36
36
 
@@ -1,3 +1,3 @@
1
1
  module Boxxspring
2
- VERSION = '2.0.3'
2
+ VERSION = '2.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxxspring
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristoph Cichocki-Romanov