Class: LocalizableModel::AnyLocalizer
- Inherits:
-
Object
- Object
- LocalizableModel::AnyLocalizer
- Defined in:
- lib/localizable_model/any_localizer.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(record) ⇒ AnyLocalizer
constructor
A new instance of AnyLocalizer.
- #method_missing(method_name, *args) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(record) ⇒ AnyLocalizer
Returns a new instance of AnyLocalizer.
7 8 9 10 |
# File 'lib/localizable_model/any_localizer.rb', line 7 def initialize(record) @record = record @attributes = record.class.localized_attributes.to_set end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/localizable_model/any_localizer.rb', line 17 def method_missing(method_name, *args) name = method_name.to_s if name.end_with?("?") attr = name.delete_suffix("?").to_sym return super unless @attributes.include?(attr) localized?(attr) else return super unless @attributes.include?(method_name) localized(method_name) end end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
5 6 7 |
# File 'lib/localizable_model/any_localizer.rb', line 5 def record @record end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
12 13 14 15 |
# File 'lib/localizable_model/any_localizer.rb', line 12 def respond_to_missing?(method_name, include_private = false) attr = method_name.to_s.delete_suffix("?") @attributes.include?(attr.to_sym) || super end |