Module: Mobility::Translates
- Defined in:
- lib/mobility/translates.rb
Overview
Defines methods for attaching backends to a class. A block can optionally be passed to accessors to configure backend (see example below).
Instance Method Summary collapse
-
#mobility_accessor(*attributes, **options) { ... } ⇒ Object
Defines mobility accessor on model class.
-
#mobility_reader(*attributes, **options) { ... } ⇒ Object
Defines mobility reader and presence method on model class.
-
#mobility_writer(*attributes, **options) { ... } ⇒ Object
Defines mobility writer on model class.
Instance Method Details
#mobility_accessor(*attributes, **options) { ... } ⇒ Object
Defines mobility accessor on model class.
|
# File 'lib/mobility/translates.rb', line 44
|
#mobility_reader(*attributes, **options) { ... } ⇒ Object
Defines mobility reader and presence method on model class.
|
# File 'lib/mobility/translates.rb', line 50
|
#mobility_writer(*attributes, **options) { ... } ⇒ Object
Defines mobility writer on model class.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mobility/translates.rb', line 61 %w[accessor reader writer].each do |method| class_eval <<-EOM, __FILE__, __LINE__ + 1 def mobility_#{method}(*args, **options, &block) attributes = Attributes.new(:#{method}, *args, options.merge(model_class: self)) attributes.backend.instance_eval &block if block_given? attributes.each do |attribute| alias_method "\#{attribute}_before_mobility", attribute if method_defined?(attribute) && #{%w[accessor reader].include? method} alias_method "\#{attribute}_before_mobility=", "\#{attribute}=" if method_defined?("\#{attribute}=") && #{%w[accessor writer].include? method} end include attributes end EOM end |