Module: Mock::ImportConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/mock/import_concern.rb
Overview
Public: We provide behavior that allows for the creation of new instances of a model from either a JSON String or a Ruby Hash.
Include this module on every model built in this app.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#has_a_has_one_relation?(relation_name) ⇒ Boolean
Public: Checks to see if we have a has_one relation of the specified name.
-
#is_singular_child_resource? ⇒ Boolean
Public: Determines if we are the destination of a has_one relation from our parent resource, assuming we even have a parent resource.
Instance Method Details
#has_a_has_one_relation?(relation_name) ⇒ Boolean
Public: Checks to see if we have a has_one relation of the specified name. The perspective is that we are the owning resource and we are advising if we have a has_one association with the given name.
relation_name - A String or Symbol, such as ‘policy’ or :policy
Returns Boolean true if the model we’re mixed into has a ‘has_one’ relation with the given name.
24 25 26 27 28 |
# File 'app/models/concerns/mock/import_concern.rb', line 24 def has_a_has_one_relation?(relation_name) has_one_keys = self.class.has_one_relations_hash.keys sanitized_relation_name = relation_name.to_s has_one_keys.include? sanitized_relation_name end |
#is_singular_child_resource? ⇒ Boolean
Public: Determines if we are the destination of a has_one relation from our parent resource, assuming we even have a parent resource.
33 34 35 36 37 38 |
# File 'app/models/concerns/mock/import_concern.rb', line 33 def is_singular_child_resource? parent_model = self.parent_resource_model_object if parent_model parent_model.has_a_has_one_relation? self.class.to_s.tableize.singularize end end |