Class: Infold::Association
- Inherits:
-
Object
- Object
- Infold::Association
- Extended by:
- Forwardable
- Includes:
- ActiveModel::Model
- Defined in:
- lib/infold/property/association.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#dependent ⇒ Object
Returns the value of attribute dependent.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#field_group ⇒ Object
readonly
Returns the value of attribute field_group.
-
#foreign_key ⇒ Object
Returns the value of attribute foreign_key.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #name_field ⇒ Object
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #belongs_to? ⇒ Boolean
- #belongs_to_show_path(object) ⇒ Object
- #find_or_initialize_field(field_name) ⇒ Object
- #has_child? ⇒ Boolean
- #has_many? ⇒ Boolean
- #has_one? ⇒ Boolean
-
#initialize(field, kind:, table:, field_group: [], name: nil, **attrs) ⇒ Association
constructor
A new instance of Association.
- #model_name(*attr) ⇒ Object
- #search_path ⇒ Object
Constructor Details
#initialize(field, kind:, table:, field_group: [], name: nil, **attrs) ⇒ Association
Returns a new instance of Association.
35 36 37 38 39 40 41 42 |
# File 'lib/infold/property/association.rb', line 35 def initialize(field, kind:, table:, field_group: [], name: nil, **attrs) @field = field @kind = kind @table = table @field_group = field_group @name = name || field.name super(**attrs) end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
16 17 18 |
# File 'lib/infold/property/association.rb', line 16 def class_name @class_name end |
#dependent ⇒ Object
Returns the value of attribute dependent.
16 17 18 |
# File 'lib/infold/property/association.rb', line 16 def dependent @dependent end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
8 9 10 |
# File 'lib/infold/property/association.rb', line 8 def field @field end |
#field_group ⇒ Object (readonly)
Returns the value of attribute field_group.
8 9 10 |
# File 'lib/infold/property/association.rb', line 8 def field_group @field_group end |
#foreign_key ⇒ Object
Returns the value of attribute foreign_key.
16 17 18 |
# File 'lib/infold/property/association.rb', line 16 def foreign_key @foreign_key end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
8 9 10 |
# File 'lib/infold/property/association.rb', line 8 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/infold/property/association.rb', line 8 def name @name end |
#name_field ⇒ Object
81 82 83 |
# File 'lib/infold/property/association.rb', line 81 def name_field @name_field.presence || 'id' end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
8 9 10 |
# File 'lib/infold/property/association.rb', line 8 def table @table end |
Instance Method Details
#belongs_to? ⇒ Boolean
44 45 46 |
# File 'lib/infold/property/association.rb', line 44 def belongs_to? kind.to_sym == :belongs_to end |
#belongs_to_show_path(object) ⇒ Object
77 78 79 |
# File 'lib/infold/property/association.rb', line 77 def belongs_to_show_path(object) "admin_#{model_name( :snake)}_path(#{object})" end |
#find_or_initialize_field(field_name) ⇒ Object
69 70 71 |
# File 'lib/infold/property/association.rb', line 69 def find_or_initialize_field(field_name) field_group.find_or_initialize_field(field_name) end |
#has_child? ⇒ Boolean
56 57 58 |
# File 'lib/infold/property/association.rb', line 56 def has_child? !belongs_to? end |
#has_many? ⇒ Boolean
48 49 50 |
# File 'lib/infold/property/association.rb', line 48 def has_many? kind.to_sym == :has_many end |
#has_one? ⇒ Boolean
52 53 54 |
# File 'lib/infold/property/association.rb', line 52 def has_one? kind.to_sym == :has_one end |
#model_name(*attr) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/infold/property/association.rb', line 60 def model_name(*attr) name = class_name.presence || self.name.singularize.camelize name = name.underscore if attr.include?(:snake) name = name.camelize if attr.include?(:camel) name = name.singularize if attr.include?(:single) name = name.pluralize if attr.include?(:multi) name end |
#search_path ⇒ Object
73 74 75 |
# File 'lib/infold/property/association.rb', line 73 def search_path "admin_#{model_name(:multi, :snake)}_path" end |