Module: Hippo::Concerns::ExportAssociations::ClassMethods
- Defined in:
- lib/hippo/concerns/export_associations.rb
Instance Method Summary collapse
-
#export_associations(*associations) ⇒ Object
Mark associations as exported, meaning they can be quered against and optionally written to.
-
#has_exported_association?(association, user) ⇒ Boolean
If the association is exported it may be queried against and it’s data included along with the parent record.
-
#has_exported_nested_attribute?(association, user) ⇒ Boolean
Does the association allow writes? True if the association has been exported and it accepts nested attributes.
Instance Method Details
#export_associations(*associations) ⇒ Object
Mark associations as exported, meaning they can be quered against and optionally written to
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hippo/concerns/export_associations.rb', line 17 def export_associations( *associations ) self.exported_associations ||= {} associations.flatten! = associations. associations.each do | assoc_name | self.exported_associations[ assoc_name.to_sym ] = if [:writable] accepts_nested_attributes_for( assoc_name, .except(:writable, :optional) ) end if false == [:optional] self.export_methods( *assoc_name, { :optional=>false }) end end end |
#has_exported_association?(association, user) ⇒ Boolean
If the association is exported it may be queried against and it’s data included along with the parent record. It may not be written to unless the :writable flag was set, in which case it’ll be allowed by has_exported_association?
35 36 37 38 39 |
# File 'lib/hippo/concerns/export_associations.rb', line 35 def has_exported_association?( association, user ) self.exported_associations && ( = self.exported_associations[ association.to_sym ] ) && evaluate_export_limit( user, :association, association, [:limit] ) end |
#has_exported_nested_attribute?(association, user) ⇒ Boolean
Does the association allow writes? True if the association has been exported and it accepts nested attributes
43 44 45 46 |
# File 'lib/hippo/concerns/export_associations.rb', line 43 def has_exported_nested_attribute?( association, user ) self.[ association.to_sym ] && self.has_exported_association?( association, user ) end |