directive 0.23.7 → 0.23.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 116a2f1626ef1e755aad317f2cfa5e7cdfdb62526727139bd9680446c347e0e3
4
- data.tar.gz: 0c40e6b40d3c033ae2b0a12f3e9e3cd609b046fda93f421c7979a709f419f415
3
+ metadata.gz: c7a24200fed2e3dd8a31ee9e6fa33cdedd30f5f2bc5947d648938fcbf7bf859f
4
+ data.tar.gz: 88678c7c7ce6ec1f373191d746a0dfa190b7681199dace0d66c94b0df234a8a6
5
5
  SHA512:
6
- metadata.gz: a68f5db1269aa351931b4a5997e782ad15f0fe391d34b65b86612f9f4b5f48e7db0e25d0c87b4d29ed011195ef4e485f9034865d4f1e132ee2ba782a16993a75
7
- data.tar.gz: 99b673ccd811832ead60da604faabc01967ae696f1812416f31957685e62f0b49a109931199581bf3ed84281c900b464185b3d2369ba5fac533cfa18f1f2eaee
6
+ metadata.gz: 6699f0fc9d6cf2a8ac56e88e76017fedb2114c61c962d343736794a7db7c57198148ef634d778586773c2126796e5da5fefb444a566d9a515c892fafc2af7790
7
+ data.tar.gz: 9fdcb7606afe882e18d90f5d6434044c45de9a2cb62dce213dd716614e5ac2766d252bec60764246a6aa60b647ce89b527a9ea17aa09b7b8e3be66a23e1508ce
@@ -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.23.8"
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.23.8
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-06-09 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.23.8
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.23.8
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