disposable 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/database.sqlite3 +0 -0
- data/lib/disposable/twin.rb +4 -2
- data/lib/disposable/version.rb +1 -1
- data/test/twin/collection_test.rb +18 -18
- data/test/twin/inherit_test.rb +2 -2
- data/test/twin/schema_test.rb +24 -0
- data/test/twin/setup_test.rb +6 -6
- 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: a9c9aa07f72bb27f1c9e16676ee32e3fd833227f
|
4
|
+
data.tar.gz: 6d4fed32a68c0fede66f34eb0e7cf879feccbc41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d1bceba1293f838c5a3878b868f0d1efcfe073354e223c3324c8ffca958cedd3c1de7525baed229f1c404e40dfb01294b32038c5988bf39ba300f357a4ad9b2
|
7
|
+
data.tar.gz: a40cd420d9bbceb1ae884ffec1343f53ba426f1d16bdbdbffc6ed9e68efef4d744619f0ce40a4e8300da24485e989338fdea581d35ecc85e18cad77fefe60a83
|
data/CHANGES.md
CHANGED
data/database.sqlite3
CHANGED
Binary file
|
data/lib/disposable/twin.rb
CHANGED
@@ -46,12 +46,13 @@ module Disposable
|
|
46
46
|
# TODO: move to Declarative, as in Representable and Reform.
|
47
47
|
def self.property(name, options={}, &block)
|
48
48
|
options[:private_name] = options.delete(:from) || name
|
49
|
-
options[:pass_options] = true
|
50
49
|
|
51
50
|
if options.delete(:virtual)
|
52
51
|
options[:writeable] = options[:readable] = false
|
53
52
|
end
|
54
53
|
|
54
|
+
options[:extend] = options[:twin] # e.g. property :album, twin: Album.
|
55
|
+
|
55
56
|
representer_class.property(name, options, &block).tap do |definition|
|
56
57
|
mod = Module.new do
|
57
58
|
define_method(name) { @fields[name.to_s] }
|
@@ -60,13 +61,14 @@ module Disposable
|
|
60
61
|
end
|
61
62
|
include mod
|
62
63
|
|
64
|
+
# FIXME: the problem here is that something like twin:{ Album } already gets evaluated here.
|
63
65
|
# property -> build_inline(representable_attrs.features)
|
64
66
|
if definition[:extend]
|
65
67
|
nested_twin = definition[:extend].evaluate(nil)
|
66
68
|
process_inline!(nested_twin, definition)
|
67
69
|
# DISCUSS: could we use build_inline's api here to inject the name feature?
|
68
70
|
|
69
|
-
definition.merge!(:
|
71
|
+
definition.merge!(twin: nested_twin)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
data/lib/disposable/version.rb
CHANGED
@@ -13,17 +13,17 @@ class TwinCollectionTest < MiniTest::Spec
|
|
13
13
|
|
14
14
|
|
15
15
|
module Twin
|
16
|
-
class Album < Disposable::Twin
|
17
|
-
property :id # DISCUSS: needed for #save.
|
18
|
-
property :name
|
19
|
-
collection :songs, :twin => lambda { |*| Song }
|
20
|
-
end
|
21
|
-
|
22
16
|
class Song < Disposable::Twin
|
23
17
|
property :id # DISCUSS: needed for #save.
|
24
18
|
property :title
|
25
19
|
property :album, :twin => Album
|
26
20
|
end
|
21
|
+
|
22
|
+
class Album < Disposable::Twin
|
23
|
+
property :id # DISCUSS: needed for #save.
|
24
|
+
property :name
|
25
|
+
collection :songs, :twin => lambda { |*| Song }
|
26
|
+
end
|
27
27
|
end
|
28
28
|
|
29
29
|
let (:song) { Model::Song.new(1, "Broken", nil) }
|
@@ -46,18 +46,6 @@ require "disposable/twin/save"
|
|
46
46
|
|
47
47
|
class TwinCollectionActiveRecordTest < MiniTest::Spec
|
48
48
|
module Twin
|
49
|
-
class Album < Disposable::Twin
|
50
|
-
property :id # DISCUSS: needed for #save.
|
51
|
-
property :name
|
52
|
-
collection :songs, :twin => lambda { |*| Song }
|
53
|
-
property :artist, twin: lambda { |*| Artist }
|
54
|
-
|
55
|
-
include Sync
|
56
|
-
include Save
|
57
|
-
include Setup
|
58
|
-
include Collection::Semantics
|
59
|
-
end
|
60
|
-
|
61
49
|
class Song < Disposable::Twin
|
62
50
|
property :id # DISCUSS: needed for #save.
|
63
51
|
property :title
|
@@ -70,6 +58,18 @@ class TwinCollectionActiveRecordTest < MiniTest::Spec
|
|
70
58
|
|
71
59
|
class Artist < Disposable::Twin
|
72
60
|
end
|
61
|
+
|
62
|
+
class Album < Disposable::Twin
|
63
|
+
property :id # DISCUSS: needed for #save.
|
64
|
+
property :name
|
65
|
+
collection :songs, :twin => lambda { |*| Song }
|
66
|
+
property :artist, twin: lambda { |*| Artist }
|
67
|
+
|
68
|
+
include Sync
|
69
|
+
include Save
|
70
|
+
include Setup
|
71
|
+
include Collection::Semantics
|
72
|
+
end
|
73
73
|
end
|
74
74
|
|
75
75
|
let (:album) { Album.create(name: "The Rest Is Silence") }
|
data/test/twin/inherit_test.rb
CHANGED
@@ -40,8 +40,8 @@ class InheritTest < MiniTest::Spec
|
|
40
40
|
|
41
41
|
# definitions are not shared.
|
42
42
|
it do
|
43
|
-
Twin::Album.representer_class.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:fromage=>:_name, :private_name=>:name, :
|
44
|
-
Twin::Compilation.representer_class.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:fromage=>:_name, :private_name=>:name, :
|
43
|
+
Twin::Album.representer_class.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:fromage=>:_name, :private_name=>:name, :parse_filter=>[], :render_filter=>[], :as=>\"name\"}>"
|
44
|
+
Twin::Compilation.representer_class.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:fromage=>:_name, :private_name=>:name, :parse_filter=>[], :render_filter=>[], :as=>\"name\", :writeable=>false, :inherit=>true}>"
|
45
45
|
end
|
46
46
|
|
47
47
|
|
data/test/twin/schema_test.rb
CHANGED
@@ -66,4 +66,28 @@ class SchemaTest < MiniTest::Spec
|
|
66
66
|
decorator.representable_attrs.get(:id).inspect.must_equal "#<Representable::Definition ==>id @options={:parse_filter=>[], :render_filter=>[], :as=>\"id\"}>"
|
67
67
|
decorator.representable_attrs.get(:title).inspect.must_equal "#<Representable::Definition ==>title @options={:writeable=>false, :deserializer=>{:skip_parse=>\"skip lambda\"}, :parse_filter=>[], :render_filter=>[], :as=>\"title\"}>"
|
68
68
|
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
class TwinSchemaTest < MiniTest::Spec
|
73
|
+
class Artist < Disposable::Twin
|
74
|
+
property :name
|
75
|
+
end
|
76
|
+
|
77
|
+
class Album < Disposable::Twin
|
78
|
+
property :artist, twin: Artist
|
79
|
+
end
|
80
|
+
|
81
|
+
it do
|
82
|
+
decorator = Disposable::Twin::Schema.from(Album, superclass: Representable::Decorator,
|
83
|
+
representer_from: lambda { |nested| nested.representer_class }
|
84
|
+
)
|
85
|
+
|
86
|
+
artist = decorator.representable_attrs.get(:artist)
|
87
|
+
options = artist.instance_variable_get(:@options)
|
88
|
+
nested_extend = options.delete(:extend)
|
89
|
+
options.inspect.must_equal "{:twin=>TwinSchemaTest::Artist, :private_name=>:artist, :parse_filter=>[], :render_filter=>[], :as=>\"artist\"}"
|
90
|
+
assert nested_extend < Representable::Decorator
|
91
|
+
nested_extend.representable_attrs.get(:name).inspect.must_equal "#<Representable::Definition ==>name @options={:private_name=>:name, :parse_filter=>[], :render_filter=>[], :as=>\"name\"}>"
|
92
|
+
end
|
69
93
|
end
|
data/test/twin/setup_test.rb
CHANGED
@@ -9,24 +9,24 @@ class TwinSetupTest < MiniTest::Spec
|
|
9
9
|
|
10
10
|
|
11
11
|
module Twin
|
12
|
-
class
|
12
|
+
class Artist < Disposable::Twin
|
13
13
|
property :id
|
14
|
-
property :name
|
15
|
-
collection :songs, twin: lambda { |*| Song }
|
16
|
-
property :artist, twin: lambda { |*| Artist }
|
17
14
|
|
18
15
|
include Setup
|
19
16
|
end
|
20
17
|
|
21
18
|
class Song < Disposable::Twin
|
22
19
|
property :id
|
23
|
-
property :composer, twin: lambda { |*| Artist }
|
20
|
+
property :composer, twin: lambda { |*| Twin::Artist }
|
24
21
|
|
25
22
|
include Setup
|
26
23
|
end
|
27
24
|
|
28
|
-
class
|
25
|
+
class Album < Disposable::Twin
|
29
26
|
property :id
|
27
|
+
property :name
|
28
|
+
collection :songs, twin: lambda { |*| Twin::Song }
|
29
|
+
property :artist, twin: lambda { |*| Twin::Artist }
|
30
30
|
|
31
31
|
include Setup
|
32
32
|
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.8
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|