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 +4 -4
- data/lib/boxxspring/operation.rb +26 -4
- data/lib/boxxspring/resources/base.rb +2 -2
- data/lib/boxxspring/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 826b0ca29329611f42824b85fc17b41e6a9c0771
|
4
|
+
data.tar.gz: 916bf662821ff5072ac0a954a1a4a0f4b93c26ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbd26015df121dffded725d3135774879a22ae93c4a83d64e6c7d03542fe47d25fe1278180e283f9a0bae02ed01a5206de246e0235e0959d81d4db44473c5145
|
7
|
+
data.tar.gz: 1c80c90180d2d5ee07fa8b4b9297172b3cc6fd95f8234279807c1d6de6b7249d1a9ee7f724dea4740182462627558ba75c9941bd4914f3c498a8d8cfa532980f
|
data/lib/boxxspring/operation.rb
CHANGED
@@ -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
|
|
data/lib/boxxspring/version.rb
CHANGED