Sha256: b19583a6add2adcbce9db9761f6f202edfd2f9cc06890aa97099f3453fe8992a

Contents?: true

Size: 666 Bytes

Versions: 23

Compression:

Stored size: 666 Bytes

Contents

module Trestle
  class Attribute
    attr_reader :name, :type, :options

    def initialize(name, type, options={})
      @name, @type, @options = name.to_sym, type, options
    end

    def array?
      options[:array] == true
    end

    class Association < Attribute
      def initialize(name, options={})
        super(name, :association, options)
      end

      def association_name
        options[:name] || name.to_s.sub(/_id$/, "")
      end

      def association_class
        options[:class].respond_to?(:call) ? options[:class].call : options[:class]
      end

      def polymorphic?
        options[:polymorphic] == true
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trestle-0.10.1 lib/trestle/attribute.rb
trestle-0.10.0 lib/trestle/attribute.rb
trestle-0.10.0.pre2 lib/trestle/attribute.rb
trestle-0.10.0.pre lib/trestle/attribute.rb
trestle-0.9.8 lib/trestle/attribute.rb
trestle-0.9.7 lib/trestle/attribute.rb
trestle-0.9.6 lib/trestle/attribute.rb
trestle-0.9.5 lib/trestle/attribute.rb
trestle-0.9.4 lib/trestle/attribute.rb
trestle-0.9.3 lib/trestle/attribute.rb
trestle-0.9.2 lib/trestle/attribute.rb
trestle-0.9.1 lib/trestle/attribute.rb
trestle-0.9.0 lib/trestle/attribute.rb
trestle-0.8.13 lib/trestle/attribute.rb
trestle-0.8.12 lib/trestle/attribute.rb
trestle-0.8.11 lib/trestle/attribute.rb
trestle-0.8.10 lib/trestle/attribute.rb
trestle-0.8.9 lib/trestle/attribute.rb
trestle-0.8.8 lib/trestle/attribute.rb
trestle-0.8.7 lib/trestle/attribute.rb