Class: RailsAdmin::Adapters::ActiveRecord::Association
- Inherits:
-
Object
- Object
- RailsAdmin::Adapters::ActiveRecord::Association
- Defined in:
- lib/rails_admin/adapters/active_record.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.
188 189 190 191 |
# File 'lib/rails_admin/adapters/active_record.rb', line 188 def initialize(association, model) @association = association @model = model end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
186 187 188 |
# File 'lib/rails_admin/adapters/active_record.rb', line 186 def association @association end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
186 187 188 |
# File 'lib/rails_admin/adapters/active_record.rb', line 186 def model @model end |
Instance Method Details
#as ⇒ Object
229 230 231 |
# File 'lib/rails_admin/adapters/active_record.rb', line 229 def as [:as].try :to_sym end |
#association? ⇒ Boolean
249 250 251 |
# File 'lib/rails_admin/adapters/active_record.rb', line 249 def association? true end |
#foreign_inverse_of ⇒ Object
225 226 227 |
# File 'lib/rails_admin/adapters/active_record.rb', line 225 def foreign_inverse_of nil end |
#foreign_key ⇒ Object
217 218 219 |
# File 'lib/rails_admin/adapters/active_record.rb', line 217 def foreign_key association.foreign_key.to_sym end |
#foreign_type ⇒ Object
221 222 223 |
# File 'lib/rails_admin/adapters/active_record.rb', line 221 def foreign_type [:foreign_type].try(:to_sym) || :"#{name}_type" if [:polymorphic] end |
#inverse_of ⇒ Object
237 238 239 |
# File 'lib/rails_admin/adapters/active_record.rb', line 237 def inverse_of [:inverse_of].try :to_sym end |
#klass ⇒ Object
205 206 207 208 209 210 211 |
# File 'lib/rails_admin/adapters/active_record.rb', line 205 def klass if [:polymorphic] polymorphic_parents(:active_record, model.name.to_s, name) || [] else association.klass end end |
#name ⇒ Object
193 194 195 |
# File 'lib/rails_admin/adapters/active_record.rb', line 193 def name association.name.to_sym end |
#nested_options ⇒ Object
245 246 247 |
# File 'lib/rails_admin/adapters/active_record.rb', line 245 def model..try { |o| o[name.to_sym] } end |
#polymorphic? ⇒ Boolean
233 234 235 |
# File 'lib/rails_admin/adapters/active_record.rb', line 233 def polymorphic? [:polymorphic] || false end |
#pretty_name ⇒ Object
197 198 199 |
# File 'lib/rails_admin/adapters/active_record.rb', line 197 def pretty_name name.to_s.tr('_', ' ').capitalize end |
#primary_key ⇒ Object
213 214 215 |
# File 'lib/rails_admin/adapters/active_record.rb', line 213 def primary_key ([:primary_key] || association.klass.primary_key).try(:to_sym) unless polymorphic? end |
#read_only? ⇒ Boolean
241 242 243 |
# File 'lib/rails_admin/adapters/active_record.rb', line 241 def read_only? (klass.all.instance_eval(&scope).readonly_value if scope.is_a? Proc) || false end |
#type ⇒ Object
201 202 203 |
# File 'lib/rails_admin/adapters/active_record.rb', line 201 def type association.macro end |