lib/trestle/attribute.rb in trestle-0.8.3 vs lib/trestle/attribute.rb in trestle-0.8.4
- old
+ new
@@ -1,54 +1,31 @@
module Trestle
class Attribute
- attr_reader :admin, :name, :type
+ attr_reader :name, :type, :options
- def initialize(admin, name, type)
- @admin, @name, @type = admin, name.to_sym, type
+ def initialize(name, type, options={})
+ @name, @type, @options = name.to_sym, type, options
end
- def association?
- type == :association
+ def array?
+ options[:array] == true
end
- def boolean?
- type == :boolean
- end
-
- def text?
- type == :text
- end
-
- def datetime?
- [:datetime, :time, :date].include?(type)
- end
-
- def primary_key?
- name.to_s == admin.model.primary_key
- end
-
- def inheritance_column?
- name.to_s == admin.model.inheritance_column
- end
-
- def counter_cache?
- name.to_s.end_with?("_count")
- end
-
class Association < Attribute
- attr_reader :association_class
-
- def initialize(admin, name, association_class)
- super(admin, name, :association)
- @association_class = association_class
+ def initialize(name, options={})
+ super(name, :association, options)
end
def association_name
- name.to_s.sub(/_id$/, "")
+ options[:name] || name.to_s.sub(/_id$/, "")
end
- def association_admin
- Trestle.admins[association_class.name.underscore.pluralize]
+ def association_class
+ options[:class].respond_to?(:call) ? options[:class].call : options[:class]
+ end
+
+ def polymorphic?
+ options[:polymorphic] == true
end
end
end
end