Module: Cockpit::Configuration::InstanceMethods
- Defined in:
- lib/cockpit/configuration.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/cockpit/configuration.rb', line 113
def method_missing(meth, *args, &block)
if args.empty?
store.get(meth)
else
store.set(meth, args.first)
end
end
|
Instance Attribute Details
#configurable ⇒ Object
Returns the value of attribute configurable.
13
14
15
|
# File 'lib/cockpit/configuration.rb', line 13
def configurable
@configurable
end
|
#setting_class ⇒ Object
Returns the value of attribute setting_class.
13
14
15
|
# File 'lib/cockpit/configuration.rb', line 13
def setting_class
@setting_class
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
93
94
95
|
# File 'lib/cockpit/configuration.rb', line 93
def []=(key, value)
store.set(key => value)
end
|
#build(&block) ⇒ Object
25
26
27
|
# File 'lib/cockpit/configuration.rb', line 25
def build(&block)
tree.instance_eval(&block) if block_given?
end
|
#clear(options = {}) ⇒ Object
97
98
99
|
# File 'lib/cockpit/configuration.rb', line 97
def clear(options = {})
store.clear(options)
end
|
#defaults ⇒ Object
50
51
52
|
# File 'lib/cockpit/configuration.rb', line 50
def defaults
store.defaults
end
|
#each_setting(&block) ⇒ Object
42
43
44
|
# File 'lib/cockpit/configuration.rb', line 42
def each_setting(&block)
tree.each_setting(&block)
end
|
#empty? ⇒ Boolean
59
60
61
|
# File 'lib/cockpit/configuration.rb', line 59
def empty?
tree.empty?
end
|
#for(configurable_id) ⇒ Object
something like this Settings.for(@user.id).set(:allow_email => params) or @user.settings(:allow_email => params)
38
39
40
|
# File 'lib/cockpit/configuration.rb', line 38
def for(configurable_id)
self
end
|
#get(path) ⇒ Object
Also known as:
[]
76
77
78
|
# File 'lib/cockpit/configuration.rb', line 76
def get(path)
store.get(path)
end
|
#get!(path) ⇒ Object
81
82
83
|
# File 'lib/cockpit/configuration.rb', line 81
def get!(path)
store.get!(path)
end
|
#initialize(*args, &block) ⇒ Object
19
20
21
22
23
|
# File 'lib/cockpit/configuration.rb', line 19
def initialize(*args, &block)
store.tree = args.
value = args
build(&block)
end
|
#inspect ⇒ Object
101
102
103
|
# File 'lib/cockpit/configuration.rb', line 101
def inspect
"<##{self.class.to_s} @tree=#{tree.inspect}/>"
end
|
#set(value) ⇒ Object
85
86
87
|
# File 'lib/cockpit/configuration.rb', line 85
def set(value)
store.set(value)
end
|
#set!(value) ⇒ Object
89
90
91
|
# File 'lib/cockpit/configuration.rb', line 89
def set!(value)
store.set!(value)
end
|
#store ⇒ Object
54
55
56
57
|
# File 'lib/cockpit/configuration.rb', line 54
def store
self.store = :memory if @store.nil?
@store
end
|
#store=(value) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/cockpit/configuration.rb', line 63
def store=(value)
options = {:configurable => configurable}
options[:tree] = @store.tree unless @store.nil?
@store = case value
when :memory
Cockpit::Store::Memory.new(self, options)
when :db
Cockpit::Store::Database.new(self, options)
else
value
end
end
|
#to_hash ⇒ Object
109
110
111
|
# File 'lib/cockpit/configuration.rb', line 109
def to_hash
store.tree.to_hash
end
|
#to_yaml ⇒ Object
105
106
107
|
# File 'lib/cockpit/configuration.rb', line 105
def to_yaml
to_hash.to_yaml
end
|
#tree ⇒ Object
46
47
48
|
# File 'lib/cockpit/configuration.rb', line 46
def tree
store.tree
end
|