Sha256: 5fc05f1279521c6449130cc7493521fa5ae49f21eecfc086c44aa1e1f1be3c34

Contents?: true

Size: 565 Bytes

Versions: 44

Compression:

Stored size: 565 Bytes

Contents

module Lookbook
  class DataParser < Service
    def initialize(input, fail_silently: false, fallback: nil)
      @input = input
      @fail_silently = fail_silently
      @fallback = fallback
    end

    def call
      result = @input.present? ? parse(@input) : @fallback
      result.is_a?(Hash) ? result.deep_symbolize_keys : result
    rescue => exception
      @fail_silently ? @fallback : raise(exception)
    end

    protected

    def parse(input)
      raise ParserError.new "DataParser must be subclassed with a :parse method defined"
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
lookbook-2.3.4 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.3.3 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.3.2 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.3.0 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.2.2 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.2.1 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.2.0 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.1.1 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.1.0 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.5 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.4 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.3 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.2 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.1 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.rc.3 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.5.5 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.5.4 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.rc.2 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.rc.1 lib/lookbook/services/data/parsers/data_parser.rb