Sha256: e5fef1f57df4a5f2c00ebdbf27fa3cdb5821b43317228bad16ea8bf6fe30fd33

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

module Granite
  module Form
    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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
granite-form-0.3.0 lib/granite/form/model/attributes/reflections/localized.rb
granite-form-0.2.0 lib/granite/form/model/attributes/reflections/localized.rb
granite-form-0.1.1 lib/granite/form/model/attributes/reflections/localized.rb
granite-form-0.1.0 lib/granite/form/model/attributes/reflections/localized.rb