Module: Tramway::Core::Associations::ObjectHelper
- Included in:
- Tramway::Core::ApplicationDecorator
- Defined in:
- app/decorators/tramway/core/associations/object_helper.rb
Instance Method Summary collapse
- #add_association_form_class_name(object, association_name) ⇒ Object
- #association_type(association) ⇒ Object
- #associations_collection(object, association_name, decorator_class_name) ⇒ Object
- #check_association(object, association_name, association) ⇒ Object
- #class_name(association) ⇒ Object
Instance Method Details
#add_association_form_class_name(object, association_name) ⇒ Object
38 39 40 |
# File 'app/decorators/tramway/core/associations/object_helper.rb', line 38 def add_association_form_class_name(object, association_name) "Admin::#{object.class.to_s.pluralize}::Add#{association_name.to_s.camelize.singularize}Form".constantize end |
#association_type(association) ⇒ Object
28 29 30 |
# File 'app/decorators/tramway/core/associations/object_helper.rb', line 28 def association_type(association) association.class.to_s.split('::').last.sub(/Reflection$/, '').underscore.to_sym end |
#associations_collection(object, association_name, decorator_class_name) ⇒ Object
32 33 34 35 36 |
# File 'app/decorators/tramway/core/associations/object_helper.rb', line 32 def associations_collection(object, association_name, decorator_class_name) object.send(association_name).active.map do |association_object| decorator_class_name.decorate association_object end end |
#check_association(object, association_name, association) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/decorators/tramway/core/associations/object_helper.rb', line 19 def check_association(object, association_name, association) return unless association.nil? Tramway::Error.raise_error( :tramway, :core, :associations, :class_helper, :model_does_not_have_association, object_class: object.class, association_name: association_name ) end |
#class_name(association) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/decorators/tramway/core/associations/object_helper.rb', line 4 def class_name(association) if association.polymorphic? object.send(association.name).class else unless association.[:class_name] Tramway::Error.raise_error( :tramway, :core, :associations, :object_helper, :please_specify_association_name, association_name: association.name, object_class: object.class, association_class_name: association.name.to_s.singularize.camelize ) end association.[:class_name] end end |