betty_resource 0.0.14 → 0.0.15
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/betty_resource/model.rb +0 -5
- data/lib/betty_resource/model/property.rb +1 -1
- data/lib/betty_resource/model/property/types/belongs_to.rb +1 -1
- data/lib/betty_resource/model/property/types/has_many.rb +2 -2
- data/lib/betty_resource/model/record.rb +25 -2
- data/lib/betty_resource/version.rb +1 -1
- data/test/unit/model/test_record.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f15b419fed1cc1e6cf1e61ee2bf9c0bdf1b0aa7
|
4
|
+
data.tar.gz: 20b4093a0fc07e120aaf822b45503208c38b2d5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15f3e06f1630cbf1ccb386566ba208d3608f349bcb29191735c9e7461e0ea0d22a54a9ef41be3d290c0cb1f3cfb26b9a430b7929c7b8275361c2bcf3082e9ce9
|
7
|
+
data.tar.gz: 24db37a18113f1dd2aedf90865b9925a5340a3bd1c194e516594d51d929e0e5d051d6c8ec5dc054f1732d58397a3ad959bf5c5631fe56a3bd2b34b440a23d1a8
|
data/lib/betty_resource/model.rb
CHANGED
@@ -9,13 +9,13 @@ module BettyResource
|
|
9
9
|
true
|
10
10
|
end
|
11
11
|
|
12
|
-
def typecast(value)
|
12
|
+
def typecast(record, value)
|
13
13
|
filter = {
|
14
14
|
'operator' => 'and',
|
15
15
|
'conditions' => [
|
16
16
|
'path' => [inverse_property.id, model.property(:id).id],
|
17
17
|
'predicate' => 'eq',
|
18
|
-
'criteria' =>
|
18
|
+
'criteria' => record.id
|
19
19
|
]
|
20
20
|
}
|
21
21
|
|
@@ -1,5 +1,23 @@
|
|
1
|
+
module DirtyAttributes
|
2
|
+
module InstanceMethods
|
3
|
+
def initialize(record)
|
4
|
+
@attributes = DirtyHashy.new({}, true, self.class.attributes, record).tap do |hashy|
|
5
|
+
dirty_map! hashy
|
6
|
+
clean_up!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
1
12
|
class DirtyHashy < HashWithIndifferentAccess
|
2
13
|
|
14
|
+
alias :org_initialize :initialize
|
15
|
+
|
16
|
+
def initialize(constructor = {}, map_methods = false, restricted_keys = nil, record)
|
17
|
+
@record = record
|
18
|
+
org_initialize(constructor = {}, map_methods = false, restricted_keys = nil)
|
19
|
+
end
|
20
|
+
|
3
21
|
alias_method :regular_reader, :[]
|
4
22
|
def [](key, mapped = false)
|
5
23
|
typecasted(key) || set_typecasted(key, regular_reader(key, mapped))
|
@@ -12,7 +30,7 @@ class DirtyHashy < HashWithIndifferentAccess
|
|
12
30
|
end
|
13
31
|
|
14
32
|
def set_typecasted(key, value)
|
15
|
-
value = @
|
33
|
+
value = @record.typecast(key, value) if @record
|
16
34
|
instance_variable_set("@typecasted_#{key}", value)
|
17
35
|
end
|
18
36
|
|
@@ -31,11 +49,16 @@ module BettyResource
|
|
31
49
|
model
|
32
50
|
end
|
33
51
|
|
52
|
+
def typecast(key, value)
|
53
|
+
property = self.class.property(key)
|
54
|
+
property ? property.typecast(self, value) : value
|
55
|
+
end
|
56
|
+
|
34
57
|
def initialize(model, attributes = {})
|
35
58
|
@model = model
|
36
59
|
@id = attributes.delete(:id) || attributes.delete('id')
|
37
60
|
@errors = {}
|
38
|
-
super()
|
61
|
+
super(self)
|
39
62
|
self.attributes = Hash[model.attributes.map { |x| [x, nil] }].merge attributes
|
40
63
|
self.attributes.instance_variable_set(:@model, model)
|
41
64
|
end
|
@@ -144,6 +144,9 @@ module Unit
|
|
144
144
|
it 'should be able to fetch a has-many value' do
|
145
145
|
group = BettyResource::Group.get(1)
|
146
146
|
assert_equal %w(Chris Daniel), group.relations.map(&:first_name).sort
|
147
|
+
|
148
|
+
group = BettyResource::Group.get(3)
|
149
|
+
assert_equal %w(), group.relations.map(&:first_name).sort
|
147
150
|
end
|
148
151
|
end
|
149
152
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betty_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chiel Wester
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-11-
|
14
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|