Sha256: 6c9bd912c11efdb148a052273f6d0f2bf6e36041e4d79670ac4d2695bb1c7872

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

module ActiveData
  module Model
    module Attributes
      module Reflections
        class ReferenceOne < Base
          def self.build(_target, generated_methods, name, *args)
            options = args.extract_options!
            generate_methods name, generated_methods
            new(name, options)
          end

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

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

              def #{name}?
                attribute('#{name}').query
              end

              def #{name}_before_type_cast
                attribute('#{name}').read_before_type_cast
              end
            RUBY
          end

          def type
            Object
          end

          def inspect_reflection
            "#{name}: (reference)"
          end

          def association
            @association ||= options[:association].to_s
          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/reference_one.rb
active_data-1.1.7 lib/active_data/model/attributes/reflections/reference_one.rb
active_data-1.1.6 lib/active_data/model/attributes/reflections/reference_one.rb
active_data-1.1.5 lib/active_data/model/attributes/reflections/reference_one.rb
active_data-1.1.4 lib/active_data/model/attributes/reflections/reference_one.rb
active_data-1.1.3 lib/active_data/model/attributes/reflections/reference_one.rb
active_data-1.1.2 lib/active_data/model/attributes/reflections/reference_one.rb
active_data-1.1.1 lib/active_data/model/attributes/reflections/reference_one.rb
active_data-1.1.0 lib/active_data/model/attributes/reflections/reference_one.rb