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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cfa318752fd70e7e5dca53b694b05ed3b0c69e3
4
- data.tar.gz: f0a203d324f8d3b7900b7432c8d766446e84e4e0
3
+ metadata.gz: 6f15b419fed1cc1e6cf1e61ee2bf9c0bdf1b0aa7
4
+ data.tar.gz: 20b4093a0fc07e120aaf822b45503208c38b2d5d
5
5
  SHA512:
6
- metadata.gz: 3cc1dd827a3f618b113cc77ad2740db50dc82474d7be02852507d41a414697fd02891ed329d631447e3ef33f929bf7916475da3cb633bfea04a2cc07d541ad11
7
- data.tar.gz: 8cebce3fed61a1facf9b0fe3a70f5b59fd75606a0b05fd3b7de9f455a1078bc0db43b1240b3475389c2f24b84d6d5d35d5bad7fca9cc7cc324309dd1c908fc92
6
+ metadata.gz: 15f3e06f1630cbf1ccb386566ba208d3608f349bcb29191735c9e7461e0ea0d22a54a9ef41be3d290c0cb1f3cfb26b9a430b7929c7b8275361c2bcf3082e9ce9
7
+ data.tar.gz: 24db37a18113f1dd2aedf90865b9925a5340a3bd1c194e516594d51d929e0e5d051d6c8ec5dc054f1732d58397a3ad959bf5c5631fe56a3bd2b34b440a23d1a8
@@ -19,11 +19,6 @@ module BettyResource
19
19
  properties.find { |p|p.name == name.to_s }
20
20
  end
21
21
 
22
- def typecast(key, value)
23
- property = self.property(key)
24
- property ? property.typecast(value) : value
25
- end
26
-
27
22
  def attributes
28
23
  properties.map(&:name)
29
24
  end
@@ -26,7 +26,7 @@ module BettyResource
26
26
  false
27
27
  end
28
28
 
29
- def typecast(value)
29
+ def typecast(record, value)
30
30
  value
31
31
  end
32
32
 
@@ -5,7 +5,7 @@ module BettyResource
5
5
  module BelongsTo
6
6
  include Association
7
7
 
8
- def typecast(value)
8
+ def typecast(record, value)
9
9
  if id = (value && value['id'])
10
10
  target_model.get(id)
11
11
  end
@@ -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' => 1
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 = @model.typecast(key, value) if @model
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
@@ -1,7 +1,7 @@
1
1
  module BettyResource
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- TINY = 14
4
+ TINY = 15
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join('.')
7
7
  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.14
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-13 00:00:00.000000000 Z
14
+ date: 2013-11-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty