Class: MadFlatter::Service

Inherits:
Object
  • Object
show all
Includes:
HashLoadable, Optionable
Defined in:
lib/mad_flatter/service.rb

Overview

This class provides functionality to load and flatten a Hash. Default options passed to the constructor may be overridden with options passed to the #execute method.

Constant Summary

Constants included from OptionsValidatable

OptionsValidatable::OPTIONS

Constants included from NamespaceOptionable

NamespaceOptionable::OPTION_NAMESPACE, NamespaceOptionable::OPTION_NAMESPACE_DEFAULT

Constants included from MetadataOptionable

MetadataOptionable::OPTION_METADATA, MetadataOptionable::OPTION_METADATA_DEFAULT, MetadataOptionable::OPTION_METADATA_EXCLUDE, MetadataOptionable::OPTION_METADATA_INCLUDE, MetadataOptionable::OPTION_METADATA_VALUES

Instance Method Summary collapse

Methods included from Optionable

#options

Methods included from OptionsValidatable

#validate_option_keys!, #validate_option_metadata!, #validate_option_namespace!, #validate_options!, #validate_options_type!

Methods included from HashInformable

#load_hash_info

Constructor Details

#initialize(options: nil) ⇒ Service

Returns a new instance of Service.



14
15
16
17
18
19
20
21
22
# File 'lib/mad_flatter/service.rb', line 14

def initialize(options: nil)
  options ||= {}

  # Accept whatever options are sent, but make sure
  # we have defaults set up. #with_defaults
  # will merge options into OptionsDefaultable::DEFAULT_OPTIONS
  # so we have defaults for any options not passed.
  self.options = Options.with_defaults options
end

Instance Method Details

#execute(hash:, options: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mad_flatter/service.rb', line 24

def execute(hash:, options: nil)
  options ||= {}

  # Merge options received into the default options passed through
  # the constructor. Options received here, will override any options
  # passed to the constructor, allowing us to retain defaut options
  # while loading, and also provide option overrides as needed.
  options = Options.with_defaults(options, defaults: self.options)

  load_hash(hash, options)
end