Class: RailsAdmin::Adapters::ActiveRecord::Association
- Inherits:
-
Object
- Object
- RailsAdmin::Adapters::ActiveRecord::Association
- Defined in:
- lib/rails_admin/adapters/active_record/association.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #as ⇒ Object
- #association? ⇒ Boolean
- #foreign_inverse_of ⇒ Object
- #foreign_key ⇒ Object
- #foreign_key_nullable? ⇒ Boolean
- #foreign_type ⇒ Object
-
#initialize(association, model) ⇒ Association
constructor
A new instance of Association.
- #inverse_of ⇒ Object
- #klass ⇒ Object
- #name ⇒ Object
- #nested_options ⇒ Object
- #polymorphic? ⇒ Boolean
- #pretty_name ⇒ Object
- #primary_key ⇒ Object
- #read_only? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(association, model) ⇒ Association
Returns a new instance of Association.
7 8 9 10 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 7 def initialize(association, model) @association = association @model = model end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
5 6 7 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 5 def association @association end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 5 def model @model end |
Instance Method Details
#as ⇒ Object
53 54 55 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 53 def as [:as].try :to_sym end |
#association? ⇒ Boolean
75 76 77 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 75 def association? true end |
#foreign_inverse_of ⇒ Object
49 50 51 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 49 def foreign_inverse_of nil end |
#foreign_key ⇒ Object
36 37 38 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 36 def foreign_key association.foreign_key.to_sym end |
#foreign_key_nullable? ⇒ Boolean
40 41 42 43 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 40 def foreign_key_nullable? return true if foreign_key.nil? || type != :has_many (column = klass.columns_hash[foreign_key.to_s]).nil? || column.null end |
#foreign_type ⇒ Object
45 46 47 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 45 def foreign_type [:foreign_type].try(:to_sym) || :"#{name}_type" if [:polymorphic] end |
#inverse_of ⇒ Object
61 62 63 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 61 def inverse_of [:inverse_of].try :to_sym end |
#klass ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 24 def klass if [:polymorphic] polymorphic_parents(:active_record, model.name.to_s, name) || [] else association.klass end end |
#name ⇒ Object
12 13 14 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 12 def name association.name.to_sym end |
#nested_options ⇒ Object
71 72 73 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 71 def model..try { |o| o[name.to_sym] } end |
#polymorphic? ⇒ Boolean
57 58 59 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 57 def polymorphic? [:polymorphic] || false end |
#pretty_name ⇒ Object
16 17 18 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 16 def pretty_name name.to_s.tr('_', ' ').capitalize end |
#primary_key ⇒ Object
32 33 34 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 32 def primary_key ([:primary_key] || association.klass.primary_key).try(:to_sym) unless polymorphic? end |
#read_only? ⇒ Boolean
65 66 67 68 69 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 65 def read_only? (klass.all.instance_eval(&scope).readonly_value if scope.is_a? Proc) || association.nested? || false end |
#type ⇒ Object
20 21 22 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 20 def type association.macro end |