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_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
48 49 50 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 48 def as [:as].try :to_sym end |
#association? ⇒ Boolean
70 71 72 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 70 def association? true end |
#foreign_inverse_of ⇒ Object
44 45 46 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 44 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_type ⇒ Object
40 41 42 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 40 def foreign_type [:foreign_type].try(:to_sym) || :"#{name}_type" if [:polymorphic] end |
#inverse_of ⇒ Object
56 57 58 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 56 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
66 67 68 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 66 def model..try { |o| o[name.to_sym] } end |
#polymorphic? ⇒ Boolean
52 53 54 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 52 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
60 61 62 63 64 |
# File 'lib/rails_admin/adapters/active_record/association.rb', line 60 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 |