Module: Moromi::RequestHeader::Core
- Extended by:
- ActiveSupport::Concern
- Included in:
- Default
- Defined in:
- lib/moromi/request_header/core.rb
Constant Summary collapse
- PROPERTIES =
%i( token bundle_identifier bundle_version_string bundle_version platform os os_version device_model device_uuid seconds_from_gmt language_code region_code ).freeze
- PROPERTY_DEFAULT_VALUES =
{ }.freeze
Instance Method Summary collapse
Instance Method Details
#initialize(headers: {}, app_name: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/moromi/request_header/core.rb', line 29 def initialize(headers: {}, app_name: nil) @app_name = app_name || self.class::default_app_name names = self.class::header_names(app_name: @app_name) self.class::PROPERTIES.each do |property| name = names[property] value = headers[name] || PROPERTY_DEFAULT_VALUES[property] public_send("#{property.to_s}=", value) rescue nil end end |
#to_hash ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/moromi/request_header/core.rb', line 42 def to_hash {}.tap do |results| self.class::header_names(app_name: @app_name).invert.each do |k, v| results[k] = public_send(v) rescue nil end end end |