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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be7cc7255ab188ade93c3a41b34fe3d3e7d3fcea
4
- data.tar.gz: 392c14ff2c4a94645c1eac6367e4d22cb93e7350
3
+ metadata.gz: a9c9aa07f72bb27f1c9e16676ee32e3fd833227f
4
+ data.tar.gz: 6d4fed32a68c0fede66f34eb0e7cf879feccbc41
5
5
  SHA512:
6
- metadata.gz: 00f77a8ce79c13ca5a55a4ca96d657b99c829d0f6f91d34f81c452d13c4a0fcf2306ca28e55bfb5390f74a5b52873f1ec49b425146f918923d5d09c80d47a253
7
- data.tar.gz: dd590bae941a3fa7e3e1b7ef74899619fef2de23cf2e154d93948873d729c21732f79d040b76d7769baa4940512a675069b23c8efa18103484529ba2f3d7afc2
6
+ metadata.gz: 1d1bceba1293f838c5a3878b868f0d1efcfe073354e223c3324c8ffca958cedd3c1de7525baed229f1c404e40dfb01294b32038c5988bf39ba300f357a4ad9b2
7
+ data.tar.gz: a40cd420d9bbceb1ae884ffec1343f53ba426f1d16bdbdbffc6ed9e68efef4d744619f0ce40a4e8300da24485e989338fdea581d35ecc85e18cad77fefe60a83
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.8
2
+
3
+ * Specifying a nested twin with `:twin` instead of a block now gets identically processed to the block.
4
+
1
5
  # 0.1.7
2
6
 
3
7
  * Removed Setup#merge_options! and hash merge as this is already been done in #setup_properties.
data/database.sqlite3 CHANGED
Binary file
@@ -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!(:twin => nested_twin)
71
+ definition.merge!(twin: nested_twin)
70
72
  end
71
73
  end
72
74
  end
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -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") }
@@ -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, :pass_options=>true, :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, :pass_options=>true, :parse_filter=>[], :render_filter=>[], :as=>\"name\", :writeable=>false, :inherit=>true}>"
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
 
@@ -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
@@ -9,24 +9,24 @@ class TwinSetupTest < MiniTest::Spec
9
9
 
10
10
 
11
11
  module Twin
12
- class Album < Disposable::Twin
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 Artist < Disposable::Twin
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.7
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-10 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber