Module: Trestle::Configurable

Extended by:
ActiveSupport::Concern
Included in:
Configuration
Defined in:
lib/trestle/configurable.rb

Defined Under Namespace

Modules: ClassMethods, Open

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object


31
32
33
34
35
# File 'lib/trestle/configurable.rb', line 31

def as_json(options=nil)
  @options.each_with_object({}) do |(k, v), h|
    h[k] = v.as_json(options)
  end
end

#assign(name, value) ⇒ Object


23
24
25
# File 'lib/trestle/configurable.rb', line 23

def assign(name, value)
  options[name.to_sym] = value
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:


7
8
9
10
# File 'lib/trestle/configurable.rb', line 7

def configure(&block)
  yield self if block_given?
  self
end

#fetch(name) ⇒ Object


12
13
14
15
16
17
18
19
20
21
# File 'lib/trestle/configurable.rb', line 12

def fetch(name)
  name = name.to_sym

  options.fetch(name) {
    if defaults.key?(name)
      value = defaults[name]
      assign(name, value)
    end
  }
end

#inspectObject


37
38
39
# File 'lib/trestle/configurable.rb', line 37

def inspect
  "#<#{self.class.name || "Anonymous(Trestle::Configurable)"}>"
end

#optionsObject


27
28
29
# File 'lib/trestle/configurable.rb', line 27

def options
  @options ||= {}
end