Module: Auth::Concerns::OwnerConcern
- Extended by:
- ActiveSupport::Concern
- Includes:
- ChiefModelConcern
- Included in:
- Shopping::CartConcern, Shopping::DiscountConcern, Shopping::PaymentConcern, Shopping::PersonalityConcern, Shopping::PlaceConcern, Shopping::ProductConcern, Image
- Defined in:
- app/models/auth/concerns/owner_concern.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#get_resource ⇒ Object
returns the resource that was associated with the object when the object was created.
- #is_applicable? ⇒ Boolean
-
#owner_matches(other_object) ⇒ Object
checks if the owner of the current object is the same as the owner of the other object passed in.
Instance Method Details
#get_resource ⇒ Object
returns the resource that was associated with the object when the object was created. it basically uses the resource_id and resource_class that were saved, when creating the resource. since resources can be created without the resource_class and resource_id being provided, it may return nil if these two are not present.
67 68 69 70 71 72 73 74 |
# File 'app/models/auth/concerns/owner_concern.rb', line 67 def get_resource return unless (self.resource_class && self.resource_id) unless owner_resource owner_resource = self.resource_class.capitalize.constantize.find(self.resource_id) end owner_resource end |
#is_applicable? ⇒ Boolean
84 85 86 87 88 |
# File 'app/models/auth/concerns/owner_concern.rb', line 84 def is_applicable? ## what if this is embedded. self.applicable end |
#owner_matches(other_object) ⇒ Object
checks if the owner of the current object is the same as the owner of the other object passed in. this is currently used in payment_concern, in a before_save validation def. this is also used in the cart_item_concern, as a before_update validation , if the parent_id is changing, where we check if the cart_item owner is the same as that of the cart.
79 80 81 82 |
# File 'app/models/auth/concerns/owner_concern.rb', line 79 def owner_matches(other_object) return false unless other_object.respond_to? :resource_id return false if self.resource_id != other_object.resource_id end |