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 +4 -4
- data/CHANGES.md +7 -0
- data/README.md +2 -0
- data/database.sqlite3 +0 -0
- data/lib/disposable/twin/setup.rb +18 -20
- data/lib/disposable/twin/struct.rb +2 -2
- data/lib/disposable/version.rb +1 -1
- data/test/twin/default_test.rb +15 -0
- data/test/twin/readable_test.rb +6 -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: be7cc7255ab188ade93c3a41b34fe3d3e7d3fcea
|
4
|
+
data.tar.gz: 392c14ff2c4a94645c1eac6367e4d22cb93e7350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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!(
|
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!(
|
24
|
-
schema.each
|
25
|
-
|
21
|
+
def setup_properties!(options)
|
22
|
+
schema.each { |dfn| setup_property!(dfn, options) }
|
23
|
+
end
|
26
24
|
|
27
|
-
|
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
|
-
|
30
|
-
|
33
|
+
setup_write!(dfn, value) # note: even readable: false will be written to twin as nil.
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
|
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
|
37
|
-
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!(
|
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
|
data/lib/disposable/version.rb
CHANGED
data/test/twin/default_test.rb
CHANGED
@@ -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
|
data/test/twin/readable_test.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2015-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|