Class: Opener::Daemons::Mapper
- Inherits:
-
Oni::Mapper
- Object
- Oni::Mapper
- Opener::Daemons::Mapper
- Defined in:
- lib/opener/daemons/mapper.rb
Overview
Maps the input/output between the daemon and the worker in such a format that both ends can work with it easily.
Constant Summary collapse
- SCHEMA_DIRECTORY =
The directory containing JSON schema files.
File.('../../../../schema', __FILE__)
- INPUT_SCHEMA =
Path to the schema file.
File.join SCHEMA_DIRECTORY, 'sqs_input.json'
Instance Attribute Summary collapse
- #component ⇒ Class readonly
- #component_options ⇒ Hash readonly
Instance Method Summary collapse
-
#initialize(component, component_options = {}) ⇒ Mapper
constructor
A new instance of Mapper.
- #map_input(message) ⇒ Hash
-
#validate_input!(input) ⇒ Object
Validates the given input Hash.
Constructor Details
#initialize(component, component_options = {}) ⇒ Mapper
Returns a new instance of Mapper.
34 35 36 37 |
# File 'lib/opener/daemons/mapper.rb', line 34 def initialize(component, = {}) @component = component @component_options = end |
Instance Attribute Details
#component ⇒ Class (readonly)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opener/daemons/mapper.rb', line 13 class Mapper < Oni::Mapper attr_reader :component, :component_options ## # The directory containing JSON schema files. # # @return [String] # SCHEMA_DIRECTORY = File.('../../../../schema', __FILE__) ## # Path to the schema file. # # @return [String] # INPUT_SCHEMA = File.join SCHEMA_DIRECTORY, 'sqs_input.json' ## # @param [Class] component # @param [Hash] component_options # def initialize(component, = {}) @component = component @component_options = end ## # @param [AWS::SQS::ReceivedMessage] message # @return [Hash] # def map_input() decoded = JSON(.body) validate_input!(decoded) return Configuration.new(component, , decoded) end ## # Validates the given input Hash. # # @param [Hash] input # @raise [JSON::Schema::ValidationError] # def validate_input!(input) JSON::Validator.validate!(INPUT_SCHEMA, input) end end |
#component_options ⇒ Hash (readonly)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opener/daemons/mapper.rb', line 13 class Mapper < Oni::Mapper attr_reader :component, :component_options ## # The directory containing JSON schema files. # # @return [String] # SCHEMA_DIRECTORY = File.('../../../../schema', __FILE__) ## # Path to the schema file. # # @return [String] # INPUT_SCHEMA = File.join SCHEMA_DIRECTORY, 'sqs_input.json' ## # @param [Class] component # @param [Hash] component_options # def initialize(component, = {}) @component = component @component_options = end ## # @param [AWS::SQS::ReceivedMessage] message # @return [Hash] # def map_input() decoded = JSON(.body) validate_input!(decoded) return Configuration.new(component, , decoded) end ## # Validates the given input Hash. # # @param [Hash] input # @raise [JSON::Schema::ValidationError] # def validate_input!(input) JSON::Validator.validate!(INPUT_SCHEMA, input) end end |
Instance Method Details
#map_input(message) ⇒ Hash
43 44 45 46 47 48 49 |
# File 'lib/opener/daemons/mapper.rb', line 43 def map_input() decoded = JSON(.body) validate_input!(decoded) return Configuration.new(component, , decoded) end |
#validate_input!(input) ⇒ Object
Validates the given input Hash.
57 58 59 |
# File 'lib/opener/daemons/mapper.rb', line 57 def validate_input!(input) JSON::Validator.validate!(INPUT_SCHEMA, input) end |