class ConfigurationDsl::Impl

Attributes

callback[RW]
configuration[RW]
module[RW]

Public Class Methods

dup_struct(struct) click to toggle source
# 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
new(object) click to toggle source
# File lib/configuration_dsl/impl.rb, line 17
def initialize(object)
  @object = object
end

Public Instance Methods

ancestors() click to toggle source
# File lib/configuration_dsl/impl.rb, line 54
def ancestors
  @object.respond_to?(:ancestors) ? @object.ancestors : [@object]
end
default_configuration() click to toggle source
# 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!() click to toggle source
# File lib/configuration_dsl/impl.rb, line 50
def default_configuration!
  @configuration = default_configuration.freeze
end
find_callback() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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