disposable 0.4.0 → 0.4.1

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: 95a247503e136210bf70026ebbf2a093de735bcc
4
- data.tar.gz: d6f1d87dc8408223b808d6fa57c4286673393fb4
3
+ metadata.gz: 1a74d3e306a9301f6e9ab4b6aea20395df6eae38
4
+ data.tar.gz: a24e79ec0ade0a96579b0a25f520deea856e4e02
5
5
  SHA512:
6
- metadata.gz: 40be1a5438aa2bf43fb992bb413dc2c503e3ead6f3698e0c91077af418704be339fa9e85d544926241eb2191a0d6226485b60534ec4ef51d2ef7c44b004d8e0b
7
- data.tar.gz: 4f7e86c71d723b08ff766360816239973955f98220c4ed0b1c93ef10c0372a56279c0a175a373f5ae4dade28c09a758e490713fe4773064bedc394a2f7dc85a9
6
+ metadata.gz: f83c3a2ae0a3a85a5114afe05dec55ca9ceab8949b5472c3eb5324951f84a6251617b34611ecf185d9153bc954e216f415d48881e72b6ec0a69b8240f906fe09
7
+ data.tar.gz: 0bba9cf7c8603f36a0c2e005215fbd66a0b2ed833002eba606df4bcd94292c421540e8f7d3c581f92ba08e72dbc0e854d47bf5b8a75cceab62aecd7abca903dc
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.4.1
2
+
3
+ * Allow `false` as a `:default` value.
4
+ * Use `Declarative::Builder` instead of `Uber::Builder`.
5
+
1
6
  # 0.4.0
2
7
 
3
8
  * In `#sync {}` with block, `nil` values will now be included in the nested hash, resulting in a hash as follows.
data/Gemfile CHANGED
@@ -2,10 +2,16 @@ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  # gem "representable", path: "../representable"
5
- gem "representable", "3.0.0"
5
+ # gem "representable", "3.0.0"
6
6
  # gem "representable", github: "apotonick/representable"
7
7
  # gem "declarative", path: "../declarative"
8
8
  # gem "declarative", github: "apotonick/declarative"
9
9
  gem "minitest-line"
10
10
 
11
- gem "activerecord", "< 5.0.0"
11
+ # gem "dry-struct"
12
+
13
+
14
+ # gem "uber", path: "../uber"
15
+ # gem "declarative-option", path: "../declarative-option"
16
+ # gem "declarative-builder", path: "../declarative-builder"
17
+ # gem "representable", path: "../representable"
@@ -17,14 +17,16 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "uber"
21
- spec.add_dependency "declarative", ">= 0.0.8", "< 1.0.0"
20
+ spec.add_dependency "uber", "< 0.2.0"
21
+ spec.add_dependency "declarative", ">= 0.0.9", "< 1.0.0"
22
+ spec.add_dependency "declarative-builder", "< 0.2.0"
23
+ spec.add_dependency "declarative-option", "< 0.2.0"
22
24
  spec.add_dependency "representable", ">= 2.4.0", "<= 3.1.0"
23
25
 
24
26
  spec.add_development_dependency "bundler", "~> 1.3"
25
27
  spec.add_development_dependency "rake"
26
28
  spec.add_development_dependency "minitest"
27
- spec.add_development_dependency "activerecord"
29
+ spec.add_development_dependency "activerecord", "4.2.5"
28
30
  spec.add_development_dependency "sqlite3"
29
31
  spec.add_development_dependency "dry-types", "~> 0.6"
30
32
  # spec.add_development_dependency "database_cleaner"
@@ -1,4 +1,4 @@
1
- require "uber/builder"
1
+ require "declarative/builder"
2
2
 
3
3
  module Disposable
4
4
  class Twin
@@ -16,13 +16,13 @@ module Disposable
16
16
  module Builder
17
17
  def self.included(base)
18
18
  base.class_eval do
19
- include Uber::Builder
19
+ include Declarative::Builder
20
20
 
21
21
  def self.build(model, options={}) # semi-public.
22
- class_builder.call(model, options).new(model, options) # Uber::Builder::class_builder.
22
+ build!(self, model, options).new(model, options) # Declarative::Builder::build!.
23
23
  end
24
24
  end
25
25
  end
26
26
  end
27
27
  end
28
- end
28
+ end
@@ -1,3 +1,5 @@
1
+ require "declarative/option"
2
+
1
3
  # TODO: allow default: -> for hashes, etc.
2
4
  module Disposable::Twin::Default
3
5
  def setup_value_for(dfn, options)
@@ -16,7 +18,7 @@ module Disposable::Twin::Default
16
18
  module ClassMethods
17
19
  private
18
20
  def build_definition(name, options={}, &block)
19
- options = options.merge(default: Uber::Options::Value.new(options[:default])) if options[:default]
21
+ options = options.merge(default: Declarative::Option(options[:default], instance_exec: true)) if options.has_key?(:default)
20
22
  super
21
23
  end
22
24
  end
@@ -3,7 +3,7 @@ require "disposable/twin/property/struct"
3
3
  class Disposable::Twin
4
4
  module Struct
5
5
  def self.included(includer)
6
- warn "[Disposable] The Struct module is deprecated, please use Property::Hash."
6
+ warn "[Disposable] The Struct module is deprecated, please use Property::Struct."
7
7
  includer.send(:include, Property::Struct)
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -116,3 +116,77 @@ class CoercionTest < MiniTest::Spec
116
116
  end
117
117
  end
118
118
  end
119
+
120
+ # this converts "" to nil and then breaks because it's strict.
121
+ # Types::Strict::String.constructor(Dry::Types::Coercions::Form.method(:to_nil))
122
+
123
+ class CoercionTypingTest < MiniTest::Spec
124
+ class Song < Disposable::Twin
125
+ include Coercion
126
+ include Setup::SkipSetter
127
+
128
+ # property :title, type: Dry::Types::Strict::String.constructor(Dry::Types::Coercions::Form.method(:to_nil))
129
+ property :title, type: Types::Strict::String.optional # this is the behavior of the "DB" data twin. this is NOT the form.
130
+
131
+ # property :name, type: Types::Form::String
132
+ end
133
+
134
+ it do
135
+ twin = Song.new(Struct.new(:title, :name).new)
136
+
137
+ # with type: Dry::Types::Strict::String
138
+ # assert_raises(Dry::Types::ConstraintError) { twin.title = nil }
139
+ twin.title = nil
140
+ twin.title.must_be_nil
141
+
142
+ twin.title = "Yo"
143
+ twin.title.must_equal "Yo"
144
+
145
+ twin.title = ""
146
+ twin.title.must_equal ""
147
+
148
+ assert_raises(Dry::Types::ConstraintError) { twin.title = :bla }
149
+ assert_raises(Dry::Types::ConstraintError) { twin.title = 1 }
150
+ end
151
+
152
+ # Form
153
+ class Form < Disposable::Twin
154
+ include Coercion
155
+ include Setup::SkipSetter
156
+
157
+
158
+ # property :title, type: Dry::Types::Strict::String.constructor(Dry::Types::Coercions::Form.method(:to_nil))
159
+ property :title, type: Types::Strict::String.optional.constructor(Dry::Types::Coercions::Form.method(:to_nil)) # this is the behavior of the "DB" data twin. this is NOT the form.
160
+
161
+ # property :name, type: Types::Form::String
162
+
163
+ property :enabled, type: Types::Form::Bool
164
+ # property :enabled, Bool.constructor(:trim!)
165
+ end
166
+ it do
167
+ twin =Form.new(Struct.new(:title, :enabled).new)
168
+
169
+ # assert_raises(Dry::Types::ConstraintError) { twin.title = nil } # in form, we either have a blank string or the key's not present at all.
170
+ twin.title = nil
171
+ twin.title.must_be_nil
172
+
173
+ twin.title = "" # nilify blank strings
174
+ twin.title.must_be_nil
175
+
176
+ twin.title = "Yo"
177
+ twin.title.must_equal "Yo"
178
+
179
+ twin.enabled = " TRUE"
180
+ twin.enabled.must_equal true
181
+ end
182
+ end
183
+
184
+
185
+ # def title=(String value) # allow obj.title = "bla"
186
+ # def title=(Nil) # allow obj.title = nil
187
+
188
+
189
+
190
+ # active = " TRUE HACK"
191
+ # how to test/validate if active is boolean?
192
+
@@ -1,7 +1,7 @@
1
1
  require "test_helper"
2
2
 
3
3
  class DefaultTest < Minitest::Spec
4
- Song = Struct.new(:title, :genre, :composer)
4
+ Song = Struct.new(:title, :new_album, :published, :genre, :composer)
5
5
  Composer = Struct.new(:name)
6
6
 
7
7
  class Twin < Disposable::Twin
@@ -12,14 +12,18 @@ class DefaultTest < Minitest::Spec
12
12
  property :composer, default: Composer.new do
13
13
  property :name, default: "NOFX"
14
14
  end
15
+ property :published, default: false
16
+ property :new_album, default: true
15
17
  end
16
18
 
17
19
  # all given.
18
20
  it do
19
- twin = Twin.new(Song.new("Anarchy Camp", "Punk", Composer.new("Nofx")))
21
+ twin = Twin.new(Song.new("Anarchy Camp", false, true, "Punk", Composer.new("Nofx")))
20
22
  twin.title.must_equal "Anarchy Camp"
21
23
  twin.genre.must_equal "Punk"
22
24
  twin.composer.name.must_equal "Nofx"
25
+ twin.published.must_equal true
26
+ twin.new_album.must_equal false
23
27
  end
24
28
 
25
29
  # defaults, please.
@@ -28,12 +32,15 @@ class DefaultTest < Minitest::Spec
28
32
  twin.title.must_equal "Medio-Core"
29
33
  twin.composer.name.must_equal "NOFX"
30
34
  twin.genre.must_equal "Punk Rock DefaultTest::Song"
35
+ twin.published.must_equal false
36
+ twin.new_album.must_equal true
31
37
  end
32
38
 
33
39
  # false value is not defaulted.
34
40
  it do
35
- twin = Twin.new(Song.new(false))
41
+ twin = Twin.new(Song.new(false, false))
36
42
  twin.title.must_equal false
43
+ twin.new_album.must_equal false
37
44
  end
38
45
 
39
46
  describe "inheritance" do
metadata CHANGED
@@ -1,36 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disposable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: declarative
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.8
33
+ version: 0.0.9
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: 1.0.0
@@ -40,10 +40,38 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.0.8
43
+ version: 0.0.9
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: declarative-builder
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.2.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: declarative-option
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.2.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.2.0
47
75
  - !ruby/object:Gem::Dependency
48
76
  name: representable
49
77
  requirement: !ruby/object:Gem::Requirement
@@ -110,16 +138,16 @@ dependencies:
110
138
  name: activerecord
111
139
  requirement: !ruby/object:Gem::Requirement
112
140
  requirements:
113
- - - ">="
141
+ - - '='
114
142
  - !ruby/object:Gem::Version
115
- version: '0'
143
+ version: 4.2.5
116
144
  type: :development
117
145
  prerelease: false
118
146
  version_requirements: !ruby/object:Gem::Requirement
119
147
  requirements:
120
- - - ">="
148
+ - - '='
121
149
  - !ruby/object:Gem::Version
122
- version: '0'
150
+ version: 4.2.5
123
151
  - !ruby/object:Gem::Dependency
124
152
  name: sqlite3
125
153
  requirement: !ruby/object:Gem::Requirement
@@ -249,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
277
  version: '0'
250
278
  requirements: []
251
279
  rubyforge_project:
252
- rubygems_version: 2.4.8
280
+ rubygems_version: 2.6.3
253
281
  signing_key:
254
282
  specification_version: 4
255
283
  summary: Decorators on top of your ORM layer with change tracking, collection semantics