Class: EventDrivenServices::HhSearch::Schemas::RestaurantSchema
- Inherits:
-
Object
- Object
- EventDrivenServices::HhSearch::Schemas::RestaurantSchema
- Includes:
- PackageLabelGenerator
- Defined in:
- app/services/event_driven_services/hh_search/schemas/restaurant_schema.rb
Constant Summary collapse
- VALID_EVENT_TYPES =
[ EventDrivenClient::Constants::INDEX_EVENT, EventDrivenClient::Constants::CREATE_EVENT, EventDrivenClient::Constants::UPDATE_EVENT, EventDrivenClient::Constants::DELETE_EVENT, ].freeze
Constants included from PackageLabelGenerator
PackageLabelGenerator::DEFAULT_LABEL_TYPE
Instance Attribute Summary collapse
-
#changed_attributes ⇒ Object
readonly
Returns the value of attribute changed_attributes.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
-
#with_availability ⇒ Object
readonly
Returns the value of attribute with_availability.
Instance Method Summary collapse
-
#initialize(restaurant, event_type, changed_attributes = {}, with_availability = false) ⇒ RestaurantSchema
constructor
A new instance of RestaurantSchema.
- #serialize ⇒ Object
Methods included from PackageLabelGenerator
#generate_label_names_for_package, #generate_labels_for_package
Constructor Details
#initialize(restaurant, event_type, changed_attributes = {}, with_availability = false) ⇒ RestaurantSchema
Returns a new instance of RestaurantSchema.
14 15 16 17 18 19 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_schema.rb', line 14 def initialize(restaurant, event_type, changed_attributes = {}, with_availability = false) @restaurant = restaurant @event_type = validate_event_type(event_type) @changed_attributes = changed_attributes @with_availability = with_availability end |
Instance Attribute Details
#changed_attributes ⇒ Object (readonly)
Returns the value of attribute changed_attributes.
5 6 7 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_schema.rb', line 5 def changed_attributes @changed_attributes end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
5 6 7 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_schema.rb', line 5 def event_type @event_type end |
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
5 6 7 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_schema.rb', line 5 def restaurant @restaurant end |
#with_availability ⇒ Object (readonly)
Returns the value of attribute with_availability.
5 6 7 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_schema.rb', line 5 def with_availability @with_availability end |
Instance Method Details
#serialize ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_schema.rb', line 21 def serialize payload = case event_type when EventDrivenClient::Constants::DELETE_EVENT default_payload when EventDrivenClient::Constants::UPDATE_EVENT # the payload should only contain the changed attributes changes_attributes_payload = if changed_attributes.select { |_, v| v.present? }.present? # If changed_attributes is not empty, use the data from changed_attributes that has non-empty values for each key changed_attributes.slice(*build_restaurant_payload.keys) else # If changed_attributes is empty, use the data from build_restaurant_payload that has non-empty values for each key build_restaurant_payload.select do |key, _| changed_attributes.key?(key) end end default_payload.merge(changes_attributes_payload) if changes_attributes_payload.present? else default_payload.merge(build_restaurant_payload) end payload.presence end |