Class: ActiveFlag::Value
- Inherits:
-
Set
- Object
- Set
- ActiveFlag::Value
show all
- Defined in:
- lib/active_flag/value.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/active_flag/value.rb', line 44
def method_missing(symbol, *args, &block)
if key = symbol.to_s.chomp!('?') and @definition.keys.include?(key.to_sym)
set?(key.to_sym)
else
super
end
end
|
Instance Method Details
#raw ⇒ Object
10
11
12
|
# File 'lib/active_flag/value.rb', line 10
def raw
@instance.read_attribute(@column)
end
|
#set(key) ⇒ Object
18
19
20
|
# File 'lib/active_flag/value.rb', line 18
def set(key)
@instance.send "#{@column}=", add(key)
end
|
#set!(key, options = {}) ⇒ Object
26
27
28
29
|
# File 'lib/active_flag/value.rb', line 26
def set!(key, options={})
set(key)
@instance.save!(options)
end
|
#set?(key) ⇒ Boolean
36
37
38
|
# File 'lib/active_flag/value.rb', line 36
def set?(key)
@instance.send(@column).include?(key)
end
|
#to_human ⇒ Object
14
15
16
|
# File 'lib/active_flag/value.rb', line 14
def to_human
@instance.send(@column).to_a.map{|key| @definition.humans[key] }
end
|
#unset(key) ⇒ Object
22
23
24
|
# File 'lib/active_flag/value.rb', line 22
def unset(key)
@instance.send "#{@column}=", delete(key)
end
|
#unset!(key, options = {}) ⇒ Object
31
32
33
34
|
# File 'lib/active_flag/value.rb', line 31
def unset!(key, options={})
unset(key)
@instance.save!(options)
end
|
#unset?(key) ⇒ Boolean
40
41
42
|
# File 'lib/active_flag/value.rb', line 40
def unset?(key)
!set?(key)
end
|
#with(instance, definition) ⇒ Object
3
4
5
6
7
8
|
# File 'lib/active_flag/value.rb', line 3
def with(instance, definition)
@instance = instance
@definition = definition
@column = definition.column
return self
end
|