Class: Traco::Attributes
- Inherits:
-
Module
- Object
- Module
- Traco::Attributes
- Defined in:
- lib/traco/attributes.rb
Class Method Summary collapse
-
.ensure_translatable_attributes(base) ⇒ Object
Only called once per class or inheritance chain (e.g. once for the superclass, not at all for subclasses).
Instance Method Summary collapse
- #included(base) ⇒ Object
-
#initialize(*attributes) ⇒ Attributes
constructor
A new instance of Attributes.
Constructor Details
#initialize(*attributes) ⇒ Attributes
Returns a new instance of Attributes.
3 4 5 6 7 8 9 10 11 |
# File 'lib/traco/attributes.rb', line 3 def initialize(*attributes) @options = attributes. @attributes = attributes.map(&:to_sym) attributes.each do |attribute| define_reader(attribute) define_writer(attribute) end end |
Class Method Details
.ensure_translatable_attributes(base) ⇒ Object
Only called once per class or inheritance chain (e.g. once for the superclass, not at all for subclasses). The separation is important if we don’t want to overwrite values if running multiple times in the same class or in different classes of an inheritance chain.
53 54 55 56 57 58 |
# File 'lib/traco/attributes.rb', line 53 def self.ensure_translatable_attributes(base) return if base.respond_to?(:translatable_attributes) base.class_attribute :translatable_attributes base.translatable_attributes = [] end |
Instance Method Details
#included(base) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/traco/attributes.rb', line 13 def included(base) self.class.ensure_translatable_attributes(base) base.translatable_attributes |= @attributes base.extend ClassMethods end |