Sha256: d929869d1fc6a6479d70e5752039881b94ba28f546549f3971e5a42d0c1487ff

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

module ActiveData
  module Model
    module Attributes
      module Reflections
        class Localized < Attribute
          def self.build(target, generated_methods, name, *args, &block)
            attribute = super(target, generated_methods, name, *args, &block)
            generate_methods name, generated_methods
            attribute
          end

          def self.generate_methods(name, target)
            target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
              def #{name}_translations
                attribute('#{name}').read
              end

              def #{name}_translations= value
                attribute('#{name}').write(value)
              end

              def #{name}
                attribute('#{name}').read_locale(self.class.locale)
              end

              def #{name}= value
                attribute('#{name}').write_locale(value, self.class.locale)
              end

              def #{name}?
                attribute('#{name}').locale_query(self.class.locale)
              end

              def #{name}_before_type_cast
                attribute('#{name}').read_locale_before_type_cast(self.class.locale)
              end
            RUBY
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_data-1.2.0 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.7 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.6 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.5 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.4 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.3 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.2 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.1 lib/active_data/model/attributes/reflections/localized.rb
active_data-1.1.0 lib/active_data/model/attributes/reflections/localized.rb