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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +4 -61
  4. data/.travis.yml +18 -11
  5. data/CHANGELOG.md +108 -43
  6. data/Gemfile +1 -0
  7. data/Rakefile +6 -0
  8. data/benchmarks/options.rb +4 -4
  9. data/benchmarks/params.rb +1 -1
  10. data/benchmarks/profiler.rb +28 -0
  11. data/benchmarks/with_types.rb +5 -9
  12. data/benchmarks/with_types_and_defaults.rb +2 -4
  13. data/benchmarks/without_options.rb +3 -3
  14. data/dry-initializer.gemspec +1 -1
  15. data/lib/dry/initializer/attribute.rb +92 -0
  16. data/lib/dry/initializer/builder.rb +76 -72
  17. data/lib/dry/initializer/exceptions/default_value_error.rb +8 -0
  18. data/lib/dry/initializer/exceptions/params_order_error.rb +8 -0
  19. data/lib/dry/initializer/exceptions/type_constraint_error.rb +7 -0
  20. data/lib/dry/initializer/option.rb +62 -0
  21. data/lib/dry/initializer/param.rb +54 -0
  22. data/lib/dry/initializer.rb +77 -13
  23. data/spec/enhancement_spec.rb +18 -0
  24. data/spec/missed_default_spec.rb +2 -2
  25. data/spec/optional_spec.rb +16 -6
  26. data/spec/options_var_spec.rb +39 -0
  27. data/spec/repetitive_definitions_spec.rb +38 -18
  28. data/spec/several_assignments_spec.rb +41 -0
  29. data/spec/type_constraint_spec.rb +6 -5
  30. metadata +15 -20
  31. data/lib/dry/initializer/errors/default_value_error.rb +0 -6
  32. data/lib/dry/initializer/errors/order_error.rb +0 -7
  33. data/lib/dry/initializer/errors/plugin_error.rb +0 -6
  34. data/lib/dry/initializer/errors/redefinition_error.rb +0 -5
  35. data/lib/dry/initializer/errors/type_constraint_error.rb +0 -5
  36. data/lib/dry/initializer/errors.rb +0 -10
  37. data/lib/dry/initializer/mixin.rb +0 -77
  38. data/lib/dry/initializer/plugins/base.rb +0 -47
  39. data/lib/dry/initializer/plugins/default_proc.rb +0 -28
  40. data/lib/dry/initializer/plugins/signature.rb +0 -28
  41. data/lib/dry/initializer/plugins/type_constraint.rb +0 -21
  42. data/lib/dry/initializer/plugins/variable_setter.rb +0 -30
  43. data/lib/dry/initializer/plugins.rb +0 -10
  44. data/lib/dry/initializer/signature.rb +0 -61
  45. data/spec/plugin_registry_spec.rb +0 -45
  46. 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