Module: Locomotive::Mounter::Fields::ClassMethods
- Defined in:
- lib/locomotive/mounter/fields.rb
Instance Method Summary collapse
-
#field(name, options = {}) ⇒ Object
Add a field to the current instance.
Instance Method Details
#field(name, options = {}) ⇒ Object
Add a field to the current instance. It creates getter/setter methods related to that field. A field can have translations if the option named localized is set to true.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/locomotive/mounter/fields.rb', line 215 def field(name, = {}) = { localized: false }.merge() @_fields ||= {} # initialize the list of fields if nil self._fields[name.to_sym] = class_eval <<-EOV def #{name} self.getter '#{name}', self.class._fields[:#{name}] end def #{name}=(value) self.setter '#{name}', value, self.class._fields[:#{name}] #, #{[:localized]} end def #{name}_localized? #{[:localized]} end EOV if [:localized] class_eval <<-EOV def #{name}_translations @#{name} || {} end def #{name}_translations=(translations) translations.each { |locale, value| self.add_locale(locale) } @#{name} = translations.symbolize_keys end EOV end end |