directive 0.23.7 → 0.25.2

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
  SHA256:
3
- metadata.gz: 116a2f1626ef1e755aad317f2cfa5e7cdfdb62526727139bd9680446c347e0e3
4
- data.tar.gz: 0c40e6b40d3c033ae2b0a12f3e9e3cd609b046fda93f421c7979a709f419f415
3
+ metadata.gz: d4cf7b87d1cd854dd8a66cc6cb93a97713c50bb7cc00448b868f9d9eb51bd6d2
4
+ data.tar.gz: b4c5a2775dbe5b46dcc1e5e9e7944fbe28f3c93f5d5ef3563b399c64ff632950
5
5
  SHA512:
6
- metadata.gz: a68f5db1269aa351931b4a5997e782ad15f0fe391d34b65b86612f9f4b5f48e7db0e25d0c87b4d29ed011195ef4e485f9034865d4f1e132ee2ba782a16993a75
7
- data.tar.gz: 99b673ccd811832ead60da604faabc01967ae696f1812416f31957685e62f0b49a109931199581bf3ed84281c900b464185b3d2369ba5fac533cfa18f1f2eaee
6
+ metadata.gz: f20e3fd3eeb8a812c8f3b43b48a89df9c750df124321c9eff9991841611c0a472c6966005bdada1d49bc4c2e2eae7dd846803f7a0e0d26c59e172f53e4069dac
7
+ data.tar.gz: 7ffbf1fa4190dd3e9adb3e205688c66853db309b44bb4f7fcc51d4469995f2a683a684b70111b1e3dc69278c6a5e1189f28367e1199ab4439d387c99704ce8fb
@@ -27,12 +27,12 @@ module Directive
27
27
  end
28
28
 
29
29
  # NOTE: options must be set up before {#configure} is called
30
- def option(*args, &block)
31
- config_class.__send__(:option, *args, &block)
30
+ def option(*args, **kwargs, &block)
31
+ config_class.__send__(:option, *args, **kwargs, &block)
32
32
  end
33
33
 
34
- def nested(*args, &block)
35
- config_class.__send__(:nested, *args, &block)
34
+ def nested(namespace, &block)
35
+ config_class.__send__(:nested, namespace, &block)
36
36
  end
37
37
 
38
38
  private
@@ -17,19 +17,23 @@ module Directive
17
17
  class << self
18
18
  private
19
19
 
20
- def option(name, *)
20
+ def option(name, *args, **kwargs)
21
+ name = name.to_sym
22
+
21
23
  _ensure_safe_option_name(name)
22
24
 
23
- super
25
+ super(name, *args, **kwargs)
24
26
  end
25
27
 
26
28
  def nested(namespace, &block)
29
+ namespace = namespace.to_sym
30
+
27
31
  _ensure_safe_option_name(namespace)
28
32
 
29
33
  nested_config_builder_for(namespace).tap do |builder|
30
34
  builder.instance_exec(&block)
31
35
 
32
- _nested_options << namespace.to_sym
36
+ _nested_options << namespace
33
37
  define_method(namespace) do |&nested_configure_block|
34
38
  builder.__send__(:configuration).tap do |nested_config|
35
39
  nested_configure_block.call(nested_config) if nested_configure_block.respond_to?(:call)
@@ -43,10 +47,10 @@ module Directive
43
47
  end
44
48
 
45
49
  def _ensure_safe_option_name(name)
46
- raise ArgumentError, "#{name.inspect} is reserved and cannot be used at a config option" if name.to_sym.in? RESERVED_WORDS
47
- raise ArgumentError, "#{name.inspect} is already in use" if _nested_options.include?(name.to_sym)
50
+ raise ArgumentError, "#{name.inspect} is reserved and cannot be used at a config option" if name.in? RESERVED_WORDS
51
+ raise ArgumentError, "#{name.inspect} is defined twice" if _nested_options.include?(name)
48
52
 
49
- puts "Warning: the config option #{name} is already defined" if _options.include?(name.to_sym) # rubocop:disable Rails/Output
53
+ puts "Warning: the config option #{name} is already defined" if _options.include?(name) # rubocop:disable Rails/Output
50
54
  end
51
55
 
52
56
  def inherited(base)
@@ -17,19 +17,15 @@ module Directive
17
17
  attr_reader :config
18
18
 
19
19
  def method_missing(method_name, *)
20
- name = method_name.to_sym
21
-
22
- return mutex.synchronize { config.public_send(name) } if config._options.map(&:to_sym).include?(name)
23
- return config._nested_builders[name].reader if config._nested_builders.key?(name)
20
+ return mutex.synchronize { config.public_send(method_name) } if config._options.include?(method_name)
21
+ return config._nested_builders[method_name].reader if config._nested_builders.key?(method_name)
24
22
 
25
23
  super
26
24
  end
27
25
 
28
26
  def respond_to_missing?(method_name, *)
29
- name = method_name.to_sym
30
-
31
- config._options.map(&:to_sym).include?(name) ||
32
- config._nested_builders.key?(name) ||
27
+ config._options.include?(method_name) ||
28
+ config._nested_builders.key?(method_name) ||
33
29
  super
34
30
  end
35
31
 
@@ -21,21 +21,35 @@ module Directive
21
21
  # it { is_expected.to define_config_option :foo }
22
22
  # it { is_expected.to define_config_option :bar, default: :baz }
23
23
  # end
24
- define :define_config_option do |option, default: nil|
25
- description { "define config option #{option.inspect}" }
26
- failure_message { "expected #{@obj} to define config option #{option.inspect} with default #{default.inspect}" }
24
+ define :define_config_option do |option, **config_options|
25
+ attr_reader :obj, :option, :default, :default_expected
26
+
27
+ description { "define config option #{option.inspect}#{with_default_message}" }
28
+ failure_message { "expected #{obj} to define config option #{option.inspect}#{with_default_message}" }
27
29
 
28
30
  match do |obj|
31
+ config_options.assert_valid_keys(:default)
32
+
29
33
  @obj = obj
34
+ @options = option
35
+
36
+ @default_expected = config_options.key?(:default)
37
+ @default = config_options[:default]
30
38
 
31
39
  if obj.is_a? Directive::ConfigObject
32
- expect(obj).to define_option option, default: default
40
+ expect(obj).to define_option option.to_sym, default: default
33
41
  else
34
42
  expect(obj).to respond_to :config
35
43
  expect(obj.config.instance_variable_get(:@config)).to be_present
36
- expect(obj.config.instance_variable_get(:@config)).to define_option option, default: default
44
+ expect(obj.config.instance_variable_get(:@config)).to define_option option.to_sym, default: default
37
45
  end
38
46
  end
47
+
48
+ def with_default_message
49
+ return unless default_expected
50
+
51
+ " with default #{default.inspect}"
52
+ end
39
53
  end
40
54
  end
41
55
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Directive
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.23.7"
5
+ VERSION = "0.25.2"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.7
4
+ version: 0.25.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Rettberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.23.7
33
+ version: 0.25.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.23.7
40
+ version: 0.25.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -104,16 +104,16 @@ dependencies:
104
104
  name: rake
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '10.0'
109
+ version: 12.3.3
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '10.0'
116
+ version: 12.3.3
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: rspec
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  requirements: []
189
- rubygems_version: 3.1.2
189
+ rubygems_version: 3.1.4
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Gem configuration made simple