Class: Spreeference::Configuration
- Inherits:
-
Object
- Object
- Spreeference::Configuration
show all
- Includes:
- Preferable
- Defined in:
- lib/spreeference/configuration.rb
Instance Method Summary
collapse
Methods included from Preferable
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/spreeference/configuration.rb', line 34
def method_missing(method, *args)
name = method.to_s.gsub('=', '')
if has_preference? name
if method.to_s =~ /=$/
set_preference(name, args.first)
else
get_preference name
end
else
super
end
end
|
Instance Method Details
5
6
7
|
# File 'lib/spreeference/configuration.rb', line 5
def configure
yield(self) if block_given?
end
|
#preferences ⇒ Object
9
10
11
|
# File 'lib/spreeference/configuration.rb', line 9
def preferences
Spreeference::ScopedStore.new(self.class.name.underscore)
end
|
#reset ⇒ Object
13
14
15
16
17
|
# File 'lib/spreeference/configuration.rb', line 13
def reset
preferences.each do |name, value|
set_preference name, preference_default(name)
end
end
|
#set(*args) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/spreeference/configuration.rb', line 23
def set(*args)
options = args.
options.each do |name, value|
set_preference name, value
end
if args.size == 2
set_preference args[0], args[1]
end
end
|