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.0.0.beta.9 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.8 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.7 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.6 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.5 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.4 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.3 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.2 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.5.3 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.1 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.5.2 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-2.0.0.beta.0 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.5.1 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.5.0 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.4.5 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.4.4 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.4.3 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.4.2 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.4.1 lib/lookbook/services/data/parsers/data_parser.rb
lookbook-1.4.0 lib/lookbook/services/data/parsers/data_parser.rb