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
50
51
52
53
54
55
56
|
# File 'lib/active_flag/value.rb', line 50
def method_missing(symbol, *args, &block)
if key = symbol.to_s.chomp('?').to_sym and @definition.keys.include?(key)
set?(key)
else
super
end
end
|
Instance Method Details
#raw ⇒ Object
12
13
14
|
# File 'lib/active_flag/value.rb', line 12
def raw
@instance.read_attribute(@column).to_i
end
|
#set(key) ⇒ Object
24
25
26
|
# File 'lib/active_flag/value.rb', line 24
def set(key)
@instance.send "#{@column}=", add(key)
end
|
#set!(key, options = {}) ⇒ Object
32
33
34
35
|
# File 'lib/active_flag/value.rb', line 32
def set!(key, options={})
set(key)
@instance.save!(**options)
end
|
#set?(key) ⇒ Boolean
42
43
44
|
# File 'lib/active_flag/value.rb', line 42
def set?(key)
include?(key)
end
|
#to_human ⇒ Object
16
17
18
|
# File 'lib/active_flag/value.rb', line 16
def to_human
to_a.map{|key| @definition.humans[key] }
end
|
#to_s ⇒ Object
20
21
22
|
# File 'lib/active_flag/value.rb', line 20
def to_s
to_a.to_s
end
|
#unset(key) ⇒ Object
28
29
30
|
# File 'lib/active_flag/value.rb', line 28
def unset(key)
@instance.send "#{@column}=", delete(key)
end
|
#unset!(key, options = {}) ⇒ Object
37
38
39
40
|
# File 'lib/active_flag/value.rb', line 37
def unset!(key, options={})
unset(key)
@instance.save!(**options)
end
|
#unset?(key) ⇒ Boolean
46
47
48
|
# File 'lib/active_flag/value.rb', line 46
def unset?(key)
!set?(key)
end
|
#with(instance, definition) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/active_flag/value.rb', line 5
def with(instance, definition)
@instance = instance
@definition = definition
@column = definition.column
return self
end
|