Class: SerialPreference::Preferenzer
- Inherits:
-
Object
- Object
- SerialPreference::Preferenzer
show all
- Defined in:
- lib/serial_preference/preferenzer.rb
Defined Under Namespace
Classes: PreferenceGroup
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Preferenzer.
7
8
9
10
11
12
|
# File 'lib/serial_preference/preferenzer.rb', line 7
def initialize
@preference_names_cache = HashWithIndifferentAccess.new
@preference_groups = []
@definition = false
activate_group
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/serial_preference/preferenzer.rb', line 24
def method_missing(name,*args,&block)
if @defintion
preference(name,args.)
else
super
end
end
|
Instance Attribute Details
#current_group ⇒ Object
Returns the value of attribute current_group.
5
6
7
|
# File 'lib/serial_preference/preferenzer.rb', line 5
def current_group
@current_group
end
|
#preference_groups ⇒ Object
Returns the value of attribute preference_groups.
5
6
7
|
# File 'lib/serial_preference/preferenzer.rb', line 5
def preference_groups
@preference_groups
end
|
Instance Method Details
#all_groups ⇒ Object
58
59
60
|
# File 'lib/serial_preference/preferenzer.rb', line 58
def all_groups
@preference_groups.map{|x|x.name}
end
|
#all_preference_definitions ⇒ Object
50
51
52
|
# File 'lib/serial_preference/preferenzer.rb', line 50
def all_preference_definitions
@preference_names_cache.values
end
|
#all_preference_names ⇒ Object
54
55
56
|
# File 'lib/serial_preference/preferenzer.rb', line 54
def all_preference_names
@preference_names_cache.keys
end
|
#definition_for(name) ⇒ Object
62
63
64
|
# File 'lib/serial_preference/preferenzer.rb', line 62
def definition_for(name)
@preference_names_cache[name]
end
|
#draw(&block) ⇒ Object
14
15
16
17
18
|
# File 'lib/serial_preference/preferenzer.rb', line 14
def draw(&block)
@defintion = true
instance_exec(&block)
@defintion = false
end
|
#preference(name, opts = {}) ⇒ Object
Also known as:
pref
38
39
40
41
42
|
# File 'lib/serial_preference/preferenzer.rb', line 38
def preference(name,opts = {})
Array(name).each do |n|
push_preference SerialPreference::PreferenceDefinition.new(n.to_sym,opts)
end
end
|
#preference_group(name, &block) ⇒ Object
45
46
47
48
|
# File 'lib/serial_preference/preferenzer.rb', line 45
def preference_group(name,&block)
activate_group(name)
instance_exec(&block)
end
|
#respond_to?(name) ⇒ Boolean
20
21
22
|
# File 'lib/serial_preference/preferenzer.rb', line 20
def respond_to?(name)
[:string, :integer, :boolean, :float].include?(name) || @preference_names_cache[name].present? || super
end
|