disposable 0.1.8 → 0.1.9

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: a9c9aa07f72bb27f1c9e16676ee32e3fd833227f
4
- data.tar.gz: 6d4fed32a68c0fede66f34eb0e7cf879feccbc41
3
+ metadata.gz: 8921eb326e4ef806db082f3a43372b32b2e76fc8
4
+ data.tar.gz: 98ae84211f0b25a33ee0035237683d647d50a579
5
5
  SHA512:
6
- metadata.gz: 1d1bceba1293f838c5a3878b868f0d1efcfe073354e223c3324c8ffca958cedd3c1de7525baed229f1c404e40dfb01294b32038c5988bf39ba300f357a4ad9b2
7
- data.tar.gz: a40cd420d9bbceb1ae884ffec1343f53ba426f1d16bdbdbffc6ed9e68efef4d744619f0ce40a4e8300da24485e989338fdea581d35ecc85e18cad77fefe60a83
6
+ metadata.gz: daad1b6f0cd51e44c4d57fad2960070bb14cf33bf13028f378151648b421b72c9c29c2dd57d3f9d47b5641b337b8dcbd22d599f35a264082f1de5a68a86035d2
7
+ data.tar.gz: 154096ab8f26fcacc523eb8569a7c0d73213b931a658e91492a51c947febc0282d114926ae32d892d2611b24dcedd1aafa039b9cf490abc75867adeb1a251edc
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.9
2
+
3
+ * The `:twin` option is no longer evaluated at compile time, only inline twins are run through `::process_inline!`. This allows specifying twin classes in lambdas for lazy-loading, and recursive twins.
4
+
1
5
  # 0.1.8
2
6
 
3
7
  * Specifying a nested twin with `:twin` instead of a block now gets identically processed to the block.
data/database.sqlite3 CHANGED
Binary file
@@ -43,38 +43,47 @@ module Disposable
43
43
  end
44
44
 
45
45
 
46
- # TODO: move to Declarative, as in Representable and Reform.
47
- def self.property(name, options={}, &block)
48
- options[:private_name] = options.delete(:from) || name
46
+ class << self
47
+ # TODO: move to Declarative, as in Representable and Reform.
48
+ def property(name, options={}, &block)
49
+ options[:private_name] = options.delete(:from) || name
49
50
 
50
- if options.delete(:virtual)
51
- options[:writeable] = options[:readable] = false
51
+ if options.delete(:virtual)
52
+ options[:writeable] = options[:readable] = false
53
+ end
54
+
55
+ options[:extend] = options[:twin] # e.g. property :album, twin: Album.
56
+
57
+ representer_class.property(name, options, &block).tap do |definition|
58
+ create_accessors(name, definition)
59
+
60
+ if definition[:extend] and !options[:twin]
61
+ # This will soon be replaced with Declarative's API. # DISCUSS: could we use build_inline's api here to inject the name feature?
62
+ nested_twin = definition[:extend].evaluate(nil)
63
+ process_inline!(nested_twin, definition)
64
+
65
+ definition.merge!(twin: nested_twin) # DISCUSS: where do we need this?
66
+ end
67
+ end
52
68
  end
53
69
 
54
- options[:extend] = options[:twin] # e.g. property :album, twin: Album.
70
+ def collection(name, options={}, &block)
71
+ property(name, options.merge(collection: true), &block)
72
+ end
55
73
 
56
- representer_class.property(name, options, &block).tap do |definition|
74
+ private
75
+ def create_accessors(name, definition)
57
76
  mod = Module.new do
58
77
  define_method(name) { @fields[name.to_s] }
59
78
  # define_method(name) { read_property(name) }
60
79
  define_method("#{name}=") { |value| write_property(name, value, definition) } # TODO: this is more like prototyping.
61
80
  end
62
81
  include mod
63
-
64
- # FIXME: the problem here is that something like twin:{ Album } already gets evaluated here.
65
- # property -> build_inline(representable_attrs.features)
66
- if definition[:extend]
67
- nested_twin = definition[:extend].evaluate(nil)
68
- process_inline!(nested_twin, definition)
69
- # DISCUSS: could we use build_inline's api here to inject the name feature?
70
-
71
- definition.merge!(twin: nested_twin)
72
- end
73
82
  end
74
- end
75
83
 
76
- def self.collection(name, options={}, &block)
77
- property(name, options.merge(collection: true), &block)
84
+ # DISCUSS: this method might disappear or change pretty soon.
85
+ def process_inline!(mod, definition)
86
+ end
78
87
  end
79
88
 
80
89
  include Setup
@@ -110,9 +119,6 @@ module Disposable
110
119
  end
111
120
  include Accessors
112
121
 
113
- # DISCUSS: this method might disappear or change pretty soon.
114
- def self.process_inline!(mod, definition)
115
- end
116
122
 
117
123
  # FIXME: this is experimental.
118
124
  module ToS
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -0,0 +1,35 @@
1
+ require "test_helper"
2
+
3
+ class ProcessInlineTest < MiniTest::Spec
4
+ Album = Struct.new(:artist, :composer, :recursive_composer)
5
+
6
+ module InlineTwin
7
+ end
8
+
9
+ class RecursiveComposerTwin < Disposable::Twin
10
+ property :composer, twin: self
11
+ end
12
+
13
+ class AlbumTwin < Disposable::Twin
14
+ def self.process_inline!(inline_class, definition)
15
+ inline_class.send :include, InlineTwin
16
+ end
17
+
18
+ property :artist do
19
+ end
20
+
21
+ property :composer, twin: ->{ ComposerTwin }
22
+
23
+ property :recursive_composer, twin: RecursiveComposerTwin
24
+ end
25
+
26
+ class ComposerTwin < Disposable::Twin
27
+ end
28
+
29
+ it do
30
+ twin = AlbumTwin.new(Album.new(Object, Object))
31
+ assert ! (twin.class < InlineTwin)
32
+ assert (twin.artist.class < InlineTwin)
33
+ assert ! (twin.composer.class < InlineTwin)
34
+ end
35
+ end
@@ -57,12 +57,12 @@ class TwinWithNestedStructTest < MiniTest::Spec
57
57
  property :title
58
58
  include Sync
59
59
 
60
- property :options, twin: true do # don't call #to_hash, this is triggered in the twin's constructor.
60
+ property :options do # don't call #to_hash, this is triggered in the twin's constructor.
61
61
  include Struct
62
62
  property :recorded
63
63
  property :released
64
64
 
65
- property :preferences, twin: true do
65
+ property :preferences do
66
66
  include Struct
67
67
  property :show_image
68
68
  property :play_teaser
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.8
4
+ version: 0.1.9
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-17 00:00:00.000000000 Z
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
@@ -195,6 +195,7 @@ files:
195
195
  - test/twin/from_test.rb
196
196
  - test/twin/inherit_test.rb
197
197
  - test/twin/option_test.rb
198
+ - test/twin/process_inline_test.rb
198
199
  - test/twin/readable_test.rb
199
200
  - test/twin/save_test.rb
200
201
  - test/twin/schema_test.rb
@@ -252,6 +253,7 @@ test_files:
252
253
  - test/twin/from_test.rb
253
254
  - test/twin/inherit_test.rb
254
255
  - test/twin/option_test.rb
256
+ - test/twin/process_inline_test.rb
255
257
  - test/twin/readable_test.rb
256
258
  - test/twin/save_test.rb
257
259
  - test/twin/schema_test.rb