Class: EventDrivenServices::HhSearch::Schemas::RestaurantTagGroupSchema
- Inherits:
-
Object
- Object
- EventDrivenServices::HhSearch::Schemas::RestaurantTagGroupSchema
- Defined in:
- app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb
Constant Summary collapse
- VALID_EVENT_TYPES =
[ EventDrivenClient::Constants::UPDATE_EVENT, EventDrivenClient::Constants::DELETE_EVENT, ].freeze
Instance Attribute Summary collapse
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#restaurant_tag_group ⇒ Object
readonly
Returns the value of attribute restaurant_tag_group.
Instance Method Summary collapse
-
#initialize(restaurant_tag_group_param, event_type) ⇒ RestaurantTagGroupSchema
constructor
A new instance of RestaurantTagGroupSchema.
-
#serialize ⇒ Hash
Serialize the restaurant tag group to a hash.
-
#serialize_as_json ⇒ String
Serialize the restaurant tag group to a JSON string.
Constructor Details
#initialize(restaurant_tag_group_param, event_type) ⇒ RestaurantTagGroupSchema
Returns a new instance of RestaurantTagGroupSchema.
12 13 14 15 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 12 def initialize(restaurant_tag_group_param, event_type) @restaurant_tag_group = validate_restaurant_tag_group(restaurant_tag_group_param) @event_type = validate_event_type(event_type) end |
Instance Attribute Details
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
5 6 7 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 5 def event_type @event_type end |
#restaurant_tag_group ⇒ Object (readonly)
Returns the value of attribute restaurant_tag_group.
5 6 7 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 5 def restaurant_tag_group @restaurant_tag_group end |
Instance Method Details
#serialize ⇒ Hash
Serialize the restaurant tag group to a hash
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 20 def serialize if event_type == EventDrivenClient::Constants::DELETE_EVENT default_payload else payload = default_payload.dup # Add title for all available locales dynamically MyLocaleManager.available_locales.each do |locale| name_attr = "name_#{locale}" if restaurant_tag_group.respond_to?(name_attr) # Use fallback to default locale for empty values payload["title_#{locale}".to_sym] = restaurant_tag_group.public_send(name_attr).presence || restaurant_tag_group.public_send("name_#{MyLocaleManager.default_locale}") end end payload end end |
#serialize_as_json ⇒ String
Serialize the restaurant tag group to a JSON string
43 44 45 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 43 def serialize_as_json serialize.to_json end |