Module: ActiveAdmin::Resource::Attributes
- Included in:
- ActiveAdmin::Resource
- Defined in:
- lib/active_admin/resource/attributes.rb
Instance Method Summary collapse
- #counter_cache_col?(c) ⇒ Boolean
- #default_attributes ⇒ Object
- #filtered_col?(c) ⇒ Boolean
- #foreign_methods ⇒ Object
- #method_for_column(c) ⇒ Object
- #primary_col?(c) ⇒ Boolean
- #reject_col?(c) ⇒ Boolean
- #sti_col?(c) ⇒ Boolean
Instance Method Details
#counter_cache_col?(c) ⇒ Boolean
39 40 41 |
# File 'lib/active_admin/resource/attributes.rb', line 39 def counter_cache_col?(c) c.name.end_with?("_count") end |
#default_attributes ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/active_admin/resource/attributes.rb', line 7 def default_attributes resource_class.columns.each_with_object({}) do |c, attrs| unless reject_col?(c) name = c.name.to_sym attrs[name] = (method_for_column(name) || name) end end end |
#filtered_col?(c) ⇒ Boolean
43 44 45 |
# File 'lib/active_admin/resource/attributes.rb', line 43 def filtered_col?(c) ActiveAdmin.application.filter_attributes.include?(c.name.to_sym) end |
#foreign_methods ⇒ Object
20 21 22 23 24 25 |
# File 'lib/active_admin/resource/attributes.rb', line 20 def foreign_methods @foreign_methods ||= resource_class.reflect_on_all_associations. select { |r| r.macro == :belongs_to }. reject { |r| r.chain.length > 2 && !r.[:polymorphic] }. index_by { |r| r.foreign_key.to_sym } end |
#method_for_column(c) ⇒ Object
16 17 18 |
# File 'lib/active_admin/resource/attributes.rb', line 16 def method_for_column(c) resource_class.respond_to?(:reflect_on_all_associations) && foreign_methods.has_key?(c) && foreign_methods[c].name.to_sym end |
#primary_col?(c) ⇒ Boolean
31 32 33 |
# File 'lib/active_admin/resource/attributes.rb', line 31 def primary_col?(c) c.name == resource_class.primary_key end |
#reject_col?(c) ⇒ Boolean
27 28 29 |
# File 'lib/active_admin/resource/attributes.rb', line 27 def reject_col?(c) primary_col?(c) || sti_col?(c) || counter_cache_col?(c) || filtered_col?(c) end |
#sti_col?(c) ⇒ Boolean
35 36 37 |
# File 'lib/active_admin/resource/attributes.rb', line 35 def sti_col?(c) c.name == resource_class.inheritance_column end |