Module: Trestle::Configurable::ClassMethods

Defined in:
lib/trestle/configurable.rb

Instance Method Summary collapse

Instance Method Details

#defaultsObject


42
43
44
# File 'lib/trestle/configurable.rb', line 42

def defaults
  @defaults ||= {}
end

#deprecated_option(name, message = nil) ⇒ Object


66
67
68
69
70
71
72
73
74
# File 'lib/trestle/configurable.rb', line 66

def deprecated_option(name, message=nil)
  define_method("#{name}=") do |value|
    ActiveSupport::Deprecation.warn(message)
  end

  define_method(name) do |*args|
    ActiveSupport::Deprecation.warn(message)
  end
end

#option(name, default = nil, opts = {}) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/trestle/configurable.rb', line 46

def option(name, default=nil, opts={})
  name = name.to_sym

  define_method("#{name}=") do |value|
    assign(name, value)
  end

  define_method(name) do |*args|
    value = fetch(name)

    if value.respond_to?(:call) && opts[:evaluate] != false
      value = value.call(*args)
    end

    value
  end

  defaults[name] = default
end