dry-initializer 0.11.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -61
- data/.travis.yml +18 -11
- data/CHANGELOG.md +108 -43
- data/Gemfile +1 -0
- data/Rakefile +6 -0
- data/benchmarks/options.rb +4 -4
- data/benchmarks/params.rb +1 -1
- data/benchmarks/profiler.rb +28 -0
- data/benchmarks/with_types.rb +5 -9
- data/benchmarks/with_types_and_defaults.rb +2 -4
- data/benchmarks/without_options.rb +3 -3
- data/dry-initializer.gemspec +1 -1
- data/lib/dry/initializer/attribute.rb +92 -0
- data/lib/dry/initializer/builder.rb +76 -72
- data/lib/dry/initializer/exceptions/default_value_error.rb +8 -0
- data/lib/dry/initializer/exceptions/params_order_error.rb +8 -0
- data/lib/dry/initializer/exceptions/type_constraint_error.rb +7 -0
- data/lib/dry/initializer/option.rb +62 -0
- data/lib/dry/initializer/param.rb +54 -0
- data/lib/dry/initializer.rb +77 -13
- data/spec/enhancement_spec.rb +18 -0
- data/spec/missed_default_spec.rb +2 -2
- data/spec/optional_spec.rb +16 -6
- data/spec/options_var_spec.rb +39 -0
- data/spec/repetitive_definitions_spec.rb +38 -18
- data/spec/several_assignments_spec.rb +41 -0
- data/spec/type_constraint_spec.rb +6 -5
- metadata +15 -20
- data/lib/dry/initializer/errors/default_value_error.rb +0 -6
- data/lib/dry/initializer/errors/order_error.rb +0 -7
- data/lib/dry/initializer/errors/plugin_error.rb +0 -6
- data/lib/dry/initializer/errors/redefinition_error.rb +0 -5
- data/lib/dry/initializer/errors/type_constraint_error.rb +0 -5
- data/lib/dry/initializer/errors.rb +0 -10
- data/lib/dry/initializer/mixin.rb +0 -77
- data/lib/dry/initializer/plugins/base.rb +0 -47
- data/lib/dry/initializer/plugins/default_proc.rb +0 -28
- data/lib/dry/initializer/plugins/signature.rb +0 -28
- data/lib/dry/initializer/plugins/type_constraint.rb +0 -21
- data/lib/dry/initializer/plugins/variable_setter.rb +0 -30
- data/lib/dry/initializer/plugins.rb +0 -10
- data/lib/dry/initializer/signature.rb +0 -61
- data/spec/plugin_registry_spec.rb +0 -45
- data/spec/renaming_options_spec.rb +0 -20
@@ -1,45 +0,0 @@
|
|
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
|
@@ -1,20 +0,0 @@
|
|
1
|
-
describe "renaming options" do
|
2
|
-
before do
|
3
|
-
class Test::Foo
|
4
|
-
extend Dry::Initializer::Mixin
|
5
|
-
|
6
|
-
option :"some foo", as: :bar
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
subject { Test::Foo.new "some foo": :BAZ }
|
11
|
-
|
12
|
-
it "renames the attribute" do
|
13
|
-
expect(subject.bar).to eq :BAZ
|
14
|
-
expect(subject).not_to respond_to :foo
|
15
|
-
end
|
16
|
-
|
17
|
-
it "renames the variable" do
|
18
|
-
expect(subject.instance_variable_get(:@bar)).to eq :BAZ
|
19
|
-
end
|
20
|
-
end
|