Sha256: 4944a293fade49fa0ef17438084d0bc4968d5459fda5e9be994d8240cb841f91

Contents?: true

Size: 1.14 KB

Versions: 11

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require_relative 'hash_loadable'
require_relative 'optionable'

module MadFlatter
  # 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.
  class Service
    include HashLoadable
    include Optionable

    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

    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mad_flatter-3.0.8 lib/mad_flatter/service.rb
mad_flatter-3.0.7 lib/mad_flatter/service.rb
mad_flatter-3.0.6 lib/mad_flatter/service.rb
mad_flatter-3.0.5 lib/mad_flatter/service.rb
mad_flatter-3.0.4 lib/mad_flatter/service.rb
mad_flatter-3.0.3 lib/mad_flatter/service.rb
mad_flatter-3.0.2 lib/mad_flatter/service.rb
mad_flatter-3.0.1 lib/mad_flatter/service.rb
mad_flatter-3.0.0 lib/mad_flatter/service.rb
mad_flatter-2.1.0 lib/mad_flatter/service.rb
mad_flatter-2.0.0 lib/mad_flatter/service.rb