Module: EnumTable::Record
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/enum_table/record.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #enum(name) ⇒ Object
- #enum!(name) ⇒ Object
- #enum_change(name) ⇒ Object
- #enum_changed?(name) ⇒ Boolean
- #enum_id(name, value) ⇒ Object
- #enum_was(name) ⇒ Object
- #query_enum(name) ⇒ Object
- #read_attribute(name) ⇒ Object
- #read_enum(name) ⇒ Object
- #write_attribute(name, value) ⇒ Object
- #write_enum(name, value) ⇒ Object
Instance Method Details
#enum(name) ⇒ Object
151 152 153 |
# File 'lib/enum_table/record.rb', line 151 def enum(name) self.class.enums[name] end |
#enum!(name) ⇒ Object
155 156 157 158 |
# File 'lib/enum_table/record.rb', line 155 def enum!(name) self.class.enums[name] or raise ArgumentError, "no such enum: #{name}" end |
#enum_change(name) ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/enum_table/record.rb', line 194 def enum_change(name) reflection = enum!(name) change = attribute_change(reflection.id_name.to_s) or return nil old_id, new_id = *change [reflection.value(old_id), reflection.value(new_id)] end |
#enum_changed?(name) ⇒ Boolean
183 184 185 186 |
# File 'lib/enum_table/record.rb', line 183 def enum_changed?(name) reflection = enum!(name) attribute_changed?(reflection.id_name.to_s) end |
#enum_id(name, value) ⇒ Object
160 161 162 |
# File 'lib/enum_table/record.rb', line 160 def enum_id(name, value) self.class.enum_id(name, value) end |
#enum_was(name) ⇒ Object
188 189 190 191 192 |
# File 'lib/enum_table/record.rb', line 188 def enum_was(name) reflection = enum!(name) id = attribute_was(reflection.id_name.to_s) reflection.value(id) end |
#query_enum(name) ⇒ Object
170 171 172 173 174 |
# File 'lib/enum_table/record.rb', line 170 def query_enum(name) reflection = enum!(name) id = read_attribute(reflection.id_name) !!reflection.value(id) end |
#read_attribute(name) ⇒ Object
202 203 204 205 206 |
# File 'lib/enum_table/record.rb', line 202 def read_attribute(name) reflection = enum(name) or return super read_enum(name) end |
#read_enum(name) ⇒ Object
164 165 166 167 168 |
# File 'lib/enum_table/record.rb', line 164 def read_enum(name) reflection = enum!(name) id = read_attribute(reflection.id_name) reflection.value(id) end |
#write_attribute(name, value) ⇒ Object
208 209 210 211 212 |
# File 'lib/enum_table/record.rb', line 208 def write_attribute(name, value) reflection = enum(name) or return super write_enum(name, value) end |
#write_enum(name, value) ⇒ Object
176 177 178 179 180 181 |
# File 'lib/enum_table/record.rb', line 176 def write_enum(name, value) reflection = enum!(name) id = reflection.id(value) write_attribute(reflection.id_name, id) value end |