Class: SpreeCmCommissioner::Places::FindWithRoute
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Places::FindWithRoute
- Defined in:
- app/finders/spree_cm_commissioner/places/find_with_route.rb
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#place_id ⇒ Object
readonly
Returns the value of attribute place_id.
-
#place_type ⇒ Object
readonly
Returns the value of attribute place_type.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(place_type:, place_id: nil, keyword: nil) ⇒ FindWithRoute
constructor
A new instance of FindWithRoute.
Constructor Details
#initialize(place_type:, place_id: nil, keyword: nil) ⇒ FindWithRoute
Returns a new instance of FindWithRoute.
25 26 27 28 29 |
# File 'app/finders/spree_cm_commissioner/places/find_with_route.rb', line 25 def initialize(place_type:, place_id: nil, keyword: nil) @place_type = place_type @place_id = place_id @keyword = keyword end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
23 24 25 |
# File 'app/finders/spree_cm_commissioner/places/find_with_route.rb', line 23 def keyword @keyword end |
#place_id ⇒ Object (readonly)
Returns the value of attribute place_id.
23 24 25 |
# File 'app/finders/spree_cm_commissioner/places/find_with_route.rb', line 23 def place_id @place_id end |
#place_type ⇒ Object (readonly)
Returns the value of attribute place_type.
23 24 25 |
# File 'app/finders/spree_cm_commissioner/places/find_with_route.rb', line 23 def place_type @place_type end |
Instance Method Details
#execute ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/finders/spree_cm_commissioner/places/find_with_route.rb', line 31 def execute return SpreeCmCommissioner::Place.none if place_type.blank? result = if place_type == 'origin' scope = SpreeCmCommissioner::Place.with_routes_as_origin place_id.present? ? scope.where(cm_routes: { destination_place_id: place_id }) : scope else scope = SpreeCmCommissioner::Place.with_routes_as_destination place_id.present? ? scope.where(cm_routes: { origin_place_id: place_id }) : scope end return SpreeCmCommissioner::Place.none if place_id.present? && !SpreeCmCommissioner::Place.exists?(place_id) # Apply keyword filter if provided result = result.where('cm_places.name ILIKE ?', "%#{keyword}%") if keyword.present? result end |