dry-initializer 0.2.1 → 0.3.0

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: 6a766e40753a382067be26c74413c5559153aa5c
4
- data.tar.gz: c42a2c954be3312dd1c319afa9cbd8c27f3651b3
3
+ metadata.gz: ae0e61fb5894f53da09eea595818f5c6d9dc5482
4
+ data.tar.gz: d4b4eb054a1a5ccaf9d8211aed807c841fe3b0a0
5
5
  SHA512:
6
- metadata.gz: c8825deefcd6da06a075b83a17fbcbafcbd0f5d4887330567b71df464979970aae455b7c9c9f4bb40a34abddfa4ffde89553712f1a2b81de249ea24009511e0a
7
- data.tar.gz: 31c7ec0f9c6b582967438cf0feb8bb270e5ac6c9028d4e587f4c68a6b5980ba6ccfde630555f9295af90477003cb49988048e2f23a7644a383bf83efcff5be11
6
+ metadata.gz: ab37761b6ef475ba335e92b2751db1276d68b67a43d2e6f69a9e6e98f5e0ba2ffeb916739d2aab863327b8ab3fc64c30569144ceba881c90108628e4e50eb065
7
+ data.tar.gz: 866ec3b26e494e5f40066e0dd8f98a926f7cd696fdda71837ff0d06f099ab83252cca2e68e175f7632fe28c34902705ea4396246a9860ad731da62742002d648
data/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ ## v0.3.0 2016-05-19
2
+
3
+ Breaks interface for adding new plugins. Register new plugin via:
4
+
5
+ ```
6
+ def self.extended(klass)
7
+ klass.register_initializer_plugin NewPlugin
8
+ end
9
+ ```
10
+
11
+ instead of:
12
+
13
+ ```
14
+ def self.extended(klass)
15
+ klass.initializer_builder.register NewPlugin
16
+ end
17
+ ```
18
+
19
+ While the private method ##initializer_builder is still accessible
20
+ its method #register doesn't mutate the builder instance.
21
+
22
+ ### Changed (backward-incompatible changes)
23
+
24
+ * Made Mixin##initializer_builder method private (@nepalez)
25
+ * Add Mixin#register_initializer_plugin(plugin) method (@nepalez)
26
+
27
+ ### Bugs Fixed
28
+
29
+ * Prevent plugin's registry from polluting superclass (@nepalez)
30
+
31
+ [Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-initializer/compare/v0.2.1..v0.3.0)
32
+
33
+ ### Internals
34
+
35
+ * Make all instances (Builder and Signature) immutable (@nepalez)
36
+ * Decouple mixin from a builder to prevent pollution (@nepalez)
37
+ * Ensure default value block can use private variables (@jeremyf)
38
+
39
+ [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-initializer/compare/v0.2.0...v0.2.1)
40
+
1
41
  ## v0.2.1 2016-05-19
2
42
 
3
43
  ### Bugs Fixed
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dry-initializer"
3
- gem.version = "0.2.1"
3
+ gem.version = "0.3.0"
4
4
  gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
5
5
  gem.email = ["hashtable@yandex.ru", "andrew.kozin@gmail.com"]
6
6
  gem.homepage = "https://github.com/dryrb/dry-initializer"
@@ -24,26 +24,33 @@ module Dry::Initializer
24
24
 
25
25
  # Defines new agrument and reloads mixin definitions
26
26
  #
27
- # @param [Module] mixin
27
+ # @param (see #call)
28
28
  # @param [#to_sym] name
29
29
  # @param [Hash<Symbol, Object>] settings
30
30
  #
31
31
  # @return [self] itself
32
32
  #
33
- def reload(mixin, name, settings)
33
+ def define(mixin, name, settings)
34
34
  signature = @signature.add(name, settings)
35
35
  parts = @parts + @plugins.map { |p| p.call(name, settings) }.compact
36
36
 
37
37
  copy do
38
38
  @signature = signature
39
39
  @parts = parts
40
-
41
- define_readers(mixin)
42
- reload_initializer(mixin)
43
- reload_callback(mixin)
40
+ call(mixin)
44
41
  end
45
42
  end
46
43
 
44
+ # Redeclares initializer and readers in the mixin module
45
+ #
46
+ # @param [Module] mixin
47
+ #
48
+ def call(mixin)
49
+ define_readers(mixin)
50
+ reload_initializer(mixin)
51
+ reload_callback(mixin)
52
+ end
53
+
47
54
  private
48
55
 
49
56
  def copy(&block)
@@ -13,7 +13,7 @@ module Dry::Initializer
13
13
  #
14
14
  def param(name, **options)
15
15
  @initializer_builder = initializer_builder
16
- .reload(self, name, option: false, **options)
16
+ .define(self, name, option: false, **options)
17
17
  self
18
18
  end
19
19
 
@@ -25,16 +25,27 @@ module Dry::Initializer
25
25
  #
26
26
  def option(name, **options)
27
27
  @initializer_builder = initializer_builder
28
- .reload(self, name, option: true, **options)
28
+ .define(self, name, option: true, **options)
29
29
  self
30
30
  end
31
31
 
32
- # @private
32
+ # Adds new plugin to the builder
33
+ #
34
+ # @param [Dry::Initializer::Plugins::Base] plugin
35
+ # @return [self] itself
36
+ #
37
+ def register_initializer_plugin(plugin)
38
+ @initializer_builder = initializer_builder.register(plugin)
39
+ initializer_builder.call(self)
40
+ self
41
+ end
42
+
43
+ private
44
+
33
45
  def initializer_builder
34
46
  @initializer_builder ||= Builder.new
35
47
  end
36
48
 
37
- # @private
38
49
  def inherited(klass)
39
50
  klass.instance_variable_set :@initializer_builder, initializer_builder.dup
40
51
  end
@@ -0,0 +1,45 @@
1
+ describe "plugin registry" do
2
+ before do
3
+ # Define a plugin
4
+ module Test::Stringifier
5
+ class Plugin < Dry::Initializer::Plugins::Base
6
+ def call
7
+ "@#{name} = @#{name}.to_s"
8
+ end
9
+ end
10
+
11
+ def self.extended(klass)
12
+ klass.register_initializer_plugin(Plugin)
13
+ end
14
+ end
15
+
16
+ # Define superclass
17
+ class Test::Foo
18
+ extend Dry::Initializer::Mixin
19
+
20
+ param :foo
21
+ end
22
+
23
+ # Apply the plugin to the subclass
24
+ class Test::Bar < Test::Foo
25
+ extend Test::Stringifier
26
+
27
+ param :bar
28
+ end
29
+ end
30
+
31
+ let(:instance_of_superclass) { Test::Foo.new :FOO }
32
+ let(:instance_of_subclass) { Test::Bar.new :FOO, :BAR }
33
+
34
+ it "does not pollute superclass" do
35
+ expect(instance_of_superclass.foo).to eql :FOO
36
+ end
37
+
38
+ it "preserves declarations made in superclass" do
39
+ expect(instance_of_subclass.foo).to eql :FOO
40
+ end
41
+
42
+ it "applies plugin to new declarations" do
43
+ expect(instance_of_subclass.bar).to eql "BAR"
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-initializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kochnev (marshall-lee)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-18 00:00:00.000000000 Z
12
+ date: 2016-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -116,6 +116,7 @@ files:
116
116
  - spec/dry/missed_default_spec.rb
117
117
  - spec/dry/object_type_constraint_spec.rb
118
118
  - spec/dry/plain_type_constraint_spec.rb
119
+ - spec/dry/plugin_registry_spec.rb
119
120
  - spec/dry/reader_spec.rb
120
121
  - spec/dry/repetitive_definitions_spec.rb
121
122
  - spec/dry/subclassing_spec.rb
@@ -155,6 +156,7 @@ test_files:
155
156
  - spec/dry/missed_default_spec.rb
156
157
  - spec/dry/object_type_constraint_spec.rb
157
158
  - spec/dry/plain_type_constraint_spec.rb
159
+ - spec/dry/plugin_registry_spec.rb
158
160
  - spec/dry/reader_spec.rb
159
161
  - spec/dry/repetitive_definitions_spec.rb
160
162
  - spec/dry/subclassing_spec.rb