glue_gun_dsl 0.1.0 → 0.1.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: 7bc70bbece9bc81c3cb8144e5911a6b48d1b72463dd2dfa4b89dbad65883d358
4
- data.tar.gz: f3f021fa01cabc567c36e224370fd34687d804867bb97f28cfc0d0eb86877c23
3
+ metadata.gz: 37182bf278dad7cd5f5db699cb9e190acba48709d53a18bad7102a02acb1987b
4
+ data.tar.gz: 4d86c00dc096b5eb90f81c3e6fe7adf0a6ed3e91e4053f0ce88ac898c9e79158
5
5
  SHA512:
6
- metadata.gz: 247ab4c8bb7bc2ce23644640c24bc9ebc1842afe343a6deec0af4077b05ff3c31987106aba8f8fa6066338fe29bf52c1ce365984627f06335b9e622efc6afece
7
- data.tar.gz: b6814e46bbb54a9490246e1b43aac4dd1bac17042b46bd0bb0ed28679bd2495cf7e2a0a14ab601823f8e9a3494dc3400f1b0509a77cc1a05577798d3a343b7a4
6
+ metadata.gz: c5c7416cc73db27881361039fc90d42e9931d8786bfa0364d41e7752b75cc56e0a7fc283a93777a7dfa83b08f71fd3e5fb3714e1223fb7a252a2d9821e95bfae
7
+ data.tar.gz: 9bf40cceec7fc4da924b5ae6f44a9ad1994e4d88adc0cf985145896bba847fd2e541e5af9f288c2adf8184b430d51e9237a400fac8724f5413467758aad3f098
data/lib/glue_gun/dsl.rb CHANGED
@@ -166,20 +166,29 @@ module GlueGun
166
166
 
167
167
  def build_dependency_attributes(option_config, dep_attributes)
168
168
  option_config.attributes.each do |attr_name, attr_config|
169
- next if dep_attributes.key?(attr_name)
169
+ # If the attribute is already provided, use it
170
+ if dep_attributes.key?(attr_name)
171
+ value = dep_attributes[attr_name]
172
+ else
173
+ value = if attr_config.source && respond_to?(attr_config.source)
174
+ send(attr_config.source)
175
+ elsif respond_to?(attr_name)
176
+ send(attr_name)
177
+ else
178
+ attr_config.default
179
+ end
170
180
 
171
- value = if attr_config.source && respond_to?(attr_config.source)
172
- send(attr_config.source)
173
- elsif respond_to?(attr_name)
174
- send(attr_name)
175
- else
176
- attr_config.default
177
- end
181
+ value = attr_config.process_value(value, self) if attr_config.respond_to?(:process_value)
178
182
 
179
- value = attr_config.process_value(value, self) if attr_config.respond_to?(:process_value)
183
+ dep_attributes[attr_name] = value
184
+ end
180
185
 
181
- dep_attributes[attr_name] = value
186
+ # After getting the value, check if it's required and nil
187
+ if value.nil? && attr_config.required
188
+ raise ArgumentError, "Missing required attribute '#{attr_name}' for #{option_config.class_name}"
189
+ end
182
190
  end
191
+
183
192
  dep_attributes
184
193
  end
185
194
 
@@ -209,7 +218,6 @@ module GlueGun
209
218
  unless default_option.attributes.keys.include?(init_args.keys.first)
210
219
  raise ArgumentError, "#{default_option.class_name} does not respond to #{init_args.keys.first}"
211
220
  end
212
-
213
221
  end
214
222
  end
215
223
 
@@ -255,11 +263,12 @@ module GlueGun
255
263
  end
256
264
 
257
265
  class ConfigAttr
258
- attr_reader :name, :default, :source, :block
266
+ attr_reader :name, :default, :required, :source, :block
259
267
 
260
- def initialize(name, default: nil, source: nil, &block)
268
+ def initialize(name, default: nil, required: false, source: nil, &block)
261
269
  @name = name.to_sym
262
270
  @default = default
271
+ @required = required
263
272
  @source = source
264
273
  @block = block
265
274
  end
@@ -289,14 +298,14 @@ module GlueGun
289
298
  @is_only = false
290
299
  end
291
300
 
292
- # Support set_class and define_attr for single-option dependencies
301
+ # Support set_class and attribute for single-option dependencies
293
302
  def set_class(class_name)
294
303
  single_option.set_class(class_name)
295
304
  set_default_option_name(:default)
296
305
  end
297
306
 
298
- def attribute(name, default: nil, source: nil, &block)
299
- single_option.attribute(name, default: default, source: source, &block)
307
+ def attribute(name, default: nil, required: false, source: nil, &block)
308
+ single_option.attribute(name, default: default, required: required, source: source, &block)
300
309
  end
301
310
 
302
311
  def get_option(name)
@@ -363,8 +372,8 @@ module GlueGun
363
372
  end
364
373
  end
365
374
 
366
- def attribute(name, default: nil, source: nil, &block)
367
- attr = ConfigAttr.new(name, default: default, source: source, &block)
375
+ def attribute(name, default: nil, required: false, source: nil, &block)
376
+ attr = ConfigAttr.new(name, default: default, required: required, source: source, &block)
368
377
  @attributes[name.to_sym] = attr
369
378
  end
370
379
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GlueGunDsl
4
- VERSION = "0.1.0"
3
+ module GlueGun
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glue_gun_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Shollenberger
@@ -50,6 +50,20 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '8'
53
+ - !ruby/object:Gem::Dependency
54
+ name: guard
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
53
67
  - !ruby/object:Gem::Dependency
54
68
  name: ostruct
55
69
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +131,7 @@ files:
117
131
  - lib/glue_gun/dsl.rb
118
132
  - lib/glue_gun/types/hash_type.rb
119
133
  - lib/glue_gun/version.rb
120
- homepage: https://github.com/brettshollenberger/glue_gun_dsl
134
+ homepage: https://github.com/brettshollenberger/glue_gun
121
135
  licenses:
122
136
  - MIT
123
137
  metadata: {}