Class: ConfigurationDsl::Impl

Inherits:
Object
  • Object
show all
Defined in:
lib/configuration_dsl/impl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#callbackObject

Returns the value of attribute callback.



3
4
5
# File 'lib/configuration_dsl/impl.rb', line 3

def callback
  @callback
end

#configurationObject

Returns the value of attribute configuration.



3
4
5
# File 'lib/configuration_dsl/impl.rb', line 3

def configuration
  @configuration
end

#moduleObject

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

#ancestorsObject



54
55
56
# File 'lib/configuration_dsl/impl.rb', line 54

def ancestors
  @object.respond_to?(:ancestors) ? @object.ancestors : [@object]
end

#default_configurationObject



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_callbackObject



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_configurationObject



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_moduleObject



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