Sha256: c9302104eb1a868bae84f2d185aebcfc2aa51ad3c051d89c9508f0b2c5d054aa

Contents?: true

Size: 663 Bytes

Versions: 39

Compression:

Stored size: 663 Bytes

Contents

module Lookbook
  class FileResolver < DataResolver
    MATCHER = /(\S+\.(json|yml))$/
    MATCH_INDEX = 1

    protected

    def resolve(input)
      path = resolve_path(input, base_dir)
      content = read_file(path)

      case path.extname
      when ".json"
        JsonParser.call(content)
      when ".yml"
        YamlParser.call(content)
      end
    end

    def read_file(path)
      File.exist?(path.to_s) ? File.read(path) : raise_error("The data file at '#{path}' could not be found")
    end

    def resolve_path(path, base_dir)
      Pathname(path.start_with?(".") ? File.expand_path(path, base_dir) : Rails.root.join(path))
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

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