disposable 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53b71c61f518f6c2e11210f479cd37258c8bf1d8
4
- data.tar.gz: 6527a70e2a954f8c490818a08c4fc2a1657f43d6
3
+ metadata.gz: be7cc7255ab188ade93c3a41b34fe3d3e7d3fcea
4
+ data.tar.gz: 392c14ff2c4a94645c1eac6367e4d22cb93e7350
5
5
  SHA512:
6
- metadata.gz: f768a7a5e0ba34502a34e40f0a13db3c81af668ffb743afbf8fe9ad2dfdec8d72d8faa5950e2b7bca742a9a4fa2e00922954b2a9ebedfdb3994e366762328d84
7
- data.tar.gz: b8efbe750912d51d9ef2ede971e4282db397fd4c3b82394d6257d23eed25f3c854f82b796ff3da8b3ad33442d7e54b23b3a68debdccfb5c3acbf174989ec58e0
6
+ metadata.gz: 00f77a8ce79c13ca5a55a4ca96d657b99c829d0f6f91d34f81c452d13c4a0fcf2306ca28e55bfb5390f74a5b52873f1ec49b425146f918923d5d09c80d47a253
7
+ data.tar.gz: dd590bae941a3fa7e3e1b7ef74899619fef2de23cf2e154d93948873d729c21732f79d040b76d7769baa4940512a675069b23c8efa18103484529ba2f3d7afc2
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.1.7
2
+
3
+ * Removed Setup#merge_options! and hash merge as this is already been done in #setup_properties.
4
+ * Every property now gets set on the twin, even if `readable: false` is set.
5
+ * `:default` and `:virtual` now work together.
6
+ * Introduced `Setup#setup_property!`.
7
+
1
8
  # 0.1.6
2
9
 
3
10
  * Added `Default`.
data/README.md CHANGED
@@ -224,6 +224,8 @@ end
224
224
 
225
225
  Default value is applied when the model's getter returns `nil`.
226
226
 
227
+ Note that `:default` also works with `:virtual` and `readable: false`.
228
+
227
229
 
228
230
  ## Collections
229
231
 
data/database.sqlite3 CHANGED
Binary file
@@ -5,14 +5,12 @@ module Disposable
5
5
  # This will result in all twin properties/collection items being twinned, and collections
6
6
  # being Collection to expose the desired public API.
7
7
  module Setup
8
- # test is in incoming hash? is nil on incoming model?
9
-
10
8
  def initialize(model, options={})
11
9
  @fields = {}
12
10
  @model = model
13
11
  @mapper = mapper_for(model) # mapper for model.
14
12
 
15
- setup_properties!(model, options)
13
+ setup_properties!(options)
16
14
  end
17
15
 
18
16
  private
@@ -20,34 +18,34 @@ module Disposable
20
18
  model
21
19
  end
22
20
 
23
- def setup_properties!(model, options)
24
- schema.each do |dfn|
25
- next if dfn[:readable] == false
21
+ def setup_properties!(options)
22
+ schema.each { |dfn| setup_property!(dfn, options) }
23
+ end
26
24
 
27
- value = setup_value_for(dfn, options)
25
+ def setup_property!(dfn, options)
26
+ value =
27
+ if options.has_key?(name = dfn.name.to_sym)
28
+ options[dfn.name.to_sym]
29
+ else
30
+ setup_value_for(dfn, options)
31
+ end
28
32
 
29
- setup_write!(dfn, value)
30
- end
33
+ setup_write!(dfn, value) # note: even readable: false will be written to twin as nil.
34
+ end
31
35
 
32
- merge_options!(options) # FIXME: call writer!!!!!!!!!!
33
- # from_hash(options) # assigns known properties from options.
36
+ def setup_value_for(dfn, options) # overridden by Default.
37
+ return if dfn[:readable] == false
38
+ read_value_for(dfn, options)
34
39
  end
35
40
 
36
- def setup_value_for(dfn, options)
37
- name = dfn.name
38
- options[name.to_sym] || mapper.send(name) # model.title.
41
+ def read_value_for(dfn, options)
42
+ mapper.send(dfn.name) # model.title.
39
43
  end
40
44
 
41
45
  def setup_write!(dfn, value)
42
46
  send(dfn.setter, value)
43
47
  end
44
48
 
45
- def merge_options!(options)
46
- # TODO: ask charliesome if that is faster with return unless options.size.
47
- options.each { |k, v| @fields[k.to_s] = v } # TODO: this merges every option, not only defined ones.
48
- end
49
-
50
-
51
49
  # Including this will _not_ use the property's setter in Setup and allow you to override it.
52
50
  module SkipSetter
53
51
  def setup_write!(dfn, value)
@@ -4,8 +4,8 @@
4
4
  #
5
5
  # Twin.new(id: 1)
6
6
  module Struct
7
- def setup_properties!(model, options={})
8
- hash_representer.new(self).from_hash(model.merge(options))
7
+ def setup_properties!(options={})
8
+ hash_representer.new(self).from_hash(@model.merge(options))
9
9
  end
10
10
 
11
11
  def hash_representer
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -34,6 +34,21 @@ class DefaultTest < Minitest::Spec
34
34
  end
35
35
  end
36
36
 
37
+ class DefaultAndVirtualTest < Minitest::Spec
38
+ class Twin < Disposable::Twin
39
+ feature Default
40
+ feature Changed
41
+
42
+ property :title, default: "0", virtual: true
43
+ end
44
+
45
+ it do
46
+ twin = Twin.new(Object.new)
47
+ twin.title.must_equal "0"
48
+ # twin.changed.must_equal []
49
+ end
50
+ end
51
+
37
52
 
38
53
  require "disposable/twin/struct"
39
54
  class DefaultWithStructTest < Minitest::Spec
@@ -54,4 +54,10 @@ class ReadableTest < MiniTest::Spec
54
54
 
55
55
  hash.must_equal("password"=> "123", "credit_card"=>{"name"=>"Jonny", "number"=>"456"})
56
56
  }
57
+
58
+ # allow passing non-readable value as option.
59
+ it do
60
+ twin = PasswordForm.new(cred, password: "open sesame!")
61
+ twin.password.must_equal "open sesame!"
62
+ end
57
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disposable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber