Class: ConfigurationDsl::Impl
- Inherits:
-
Object
- Object
- ConfigurationDsl::Impl
- Defined in:
- lib/configuration_dsl/impl.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#module ⇒ Object
Returns the value of attribute module.
Class Method Summary collapse
Instance Method Summary collapse
- #ancestors ⇒ Object
- #default_configuration ⇒ Object
- #default_configuration! ⇒ Object
- #find_callback ⇒ Object
- #find_configuration ⇒ Object
- #find_module ⇒ Object
-
#initialize(object) ⇒ Impl
constructor
A new instance of Impl.
Constructor Details
#initialize(object) ⇒ Impl
Returns a new instance of Impl.
17 18 19 |
# File 'lib/configuration_dsl/impl.rb', line 17 def initialize(object) @object = object end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
3 4 5 |
# File 'lib/configuration_dsl/impl.rb', line 3 def callback @callback end |
#configuration ⇒ Object
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/configuration_dsl/impl.rb', line 3 def configuration @configuration end |
#module ⇒ Object
Returns the value of attribute module.
3 4 5 |
# File 'lib/configuration_dsl/impl.rb', line 3 def module @module end |
Class Method Details
.dup_struct(struct) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/configuration_dsl/impl.rb', line 5 def self.dup_struct(struct) members = struct.members.collect{ |member| member.to_sym } # Normalize between Ruby versions. values = struct.values.collect do |value| if value.kind_of?(Class) value else value.dup rescue value end end Struct.new(*members).new(*values) end |
Instance Method Details
#ancestors ⇒ Object
54 55 56 |
# File 'lib/configuration_dsl/impl.rb', line 54 def ancestors @object.respond_to?(:ancestors) ? @object.ancestors : [@object] end |
#default_configuration ⇒ Object
45 46 47 48 |
# File 'lib/configuration_dsl/impl.rb', line 45 def default_configuration defaults = find_module.const_get(:DEFAULTS) Struct.new(*defaults.keys).new(*defaults.values) end |
#default_configuration! ⇒ Object
50 51 52 |
# File 'lib/configuration_dsl/impl.rb', line 50 def default_configuration! @configuration = default_configuration.freeze end |
#find_callback ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/configuration_dsl/impl.rb', line 29 def find_callback ancestors.each do |object| next unless (impl = object.instance_variable_get(:@configuration_dsl)) return impl.callback if impl.callback end nil end |
#find_configuration ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/configuration_dsl/impl.rb', line 37 def find_configuration ancestors.each do |object| next unless (impl = object.instance_variable_get(:@configuration_dsl)) return impl.configuration if impl.configuration end nil end |
#find_module ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/configuration_dsl/impl.rb', line 21 def find_module ancestors.each do |object| next unless (impl = object.instance_variable_get(:@configuration_dsl)) return impl.module if impl.module end nil end |