Helper methods

kostyantyn edited this page Sep 7, 2012 · 4 revisions

.hydra_attributes

Return ActiveRecord::Relation object with prepared query to receive attributes for current entity

Product.hydra_attributes # return attribute models
Product.hydra_attributes.create(name: 'title', backend_type: 'string') # create attributes
Product.hydra_attributes.map(&:destroy) # destroy all attributes

.hydra_attribute(identifier)

Find attribute by ID or name. Return nil for unknown attribute.

Product.hydra_attribute('title')
# <HydraAttribute::HydraAttribute...>

Product.hydra_attribute(10)
# nil

.hydra_attribute_backend_types

Return array of attribute backend types for current entity. This method is cacheable so it is better to use it than determine values from .hydra_attributes object.

Product.hydra_attribute_backend_types
# ["string", "integer"]

.hydra_attribute_names

Return array of attribute names for current entity. This method is cacheable so it is better to use it than determine values from .hydra_attributes object.

Product.hydra_attribute_names
# ["title", "price"]

.hydra_attribute_ids

Return array of attribute ids for current entity. This method is cacheable so it is better to use it than determine values from .hydra_attributes object.

Product.hydra_attribute_ids
# [1, 2, 4]

.hydra_attributes_by_backend_type

Return hash where keys are backend types and values are array of attributes. This method is cacheable so it is better to use it than determine values from .hydra_attributes object.

Product.hydra_attributes_by_backend_type
# {"string"=>[<HydraAttribute::HydraAttribute...>, ...]}

.hydra_attribute_names_by_backend_type

Return hash where keys are backend types and values are array of attribute names. This method is cacheable so it is better to use it than determine values from .hydra_attributes object.

Product.hydra_attribute_names_by_backend_type
# {"string"=>["title", "price"]}

.hydra_attribute_ids_by_backend_type

Return hash where keys are backend types and values are array of attribute ids. This method is cacheable so it is better to use it than determine values from .hydra_attributes object.

Product.hydra_attribute_ids_by_backend_type
# {"string"=>[1, 2, 4]}

.hydra_attributes_for_backend_type(backend_type)

Return array of attributes for specific backend type.

Product.hydra_attrbiutes_for_backend_type('string')
# [<HydraAttribute::HydraAttribute...>, ...]

Product.hydra_attrbiutes_for_backend_type('integer')
# []

.hydra_attribute_names_for_backend_type(backend_type)

Return array of attribute names for specific backend type.

Product.hydra_attrbiute_names_for_backend_type('string')
# ['title', 'code']

.hydra_attribute_ids_for_backend_type(backend_type)

Return array of attribute ids for specific backend type.

Product.hydra_attrbiute_ids_for_backend_type('string')
# [1, 4]

.hydra_sets

Return ActiveRecord::Relation object with prepared query to receive attribute sets for current entity

Product.hydra_sets # return attribute set models
Product.hydra_sets.create(name: 'Default') # create attribute set
Product.hydra_sets.map(&:destroy) # destroy all attribute sets

.hydra_set(identifier)

Find attribute set by ID or name for current entity.

Product.hydra_set('Default')
# <HydraAttribute::HydraSet...>

Product.hydra_set(10)
# nil

.hydra_set_ids

Return array with all attribute set ids for current entity.

Product.hydra_set_ids
# [1, 2, 10]

.hydra_set_names

Return array with all attribute set names for current entity.

Product.hydra_set_names
# ["Default", "General"]

.hydra_set_attributes(hydra_set_identifier)

Return collection of attributes which are assigned to current attribute set. If current attribute set doesn't exist, return all attributes for current entity.

Product.hydra_set_attributes('Default') # return attributes for attribute set
Product.hydra_set_attributes('Fake') # the same as Prodct.hydra_attributes

.hydra_set_attribute_backend_types(hydra_set_identifier)

Return array of attribute backend types which are assigned to current attribute set. If current attribute set doesn't exist, return all attribute backend types for current entity.

Product.hydra_set_attribute_backend_types('Default') # return attribute backend types which are assigned to current attribute set
Product.hydra_set_attribute_backend_types('Fake') # The same as Product.hydra_attribute_backend_types

.hydra_set_attribute_ids(hydra_set_identifier)

Return array of attribute ids which are assigned to current attribute set. If current attribute set doesn't exist, return all attribute ids for current entity.

Product.hydra_set_attribute_ids('Default') # return attribute ids which are assigned to current attribute set
Product.hydra_set_attribute_ids('Fake') # The same as Product.hydra_attribute_ids

.hydra_set_attribute_names(hydra_set_identifier)

Return array of attribute names which are assigned to current attribute set. If current attribute set doesn't exist, return all attribute ids for current entity.

Product.hydra_set_attribute_names('Default') # return attribute names which are assigned to current attribute set
Product.hydra_set_attribute_names('Fake') # The same as Product.hydra_attribute_names