Sha256: 3bb5cc2f0c5e02c8aad25f552e65345b24e147a6225fe4cb396cc1b16dfae9b5

Contents?: true

Size: 612 Bytes

Versions: 11

Compression:

Stored size: 612 Bytes

Contents

module Lurker
  module Json
    class Reader
      attr_reader :path

      def initialize(path)
        @path = path
        @attempts_left = 1
      end

      def read
        return YAML.load_file(@path) unless @path.match(/\.erb$/)

        context = Lurker::ErbSchemaContext.new
        erb = ERB.new(IO.read @path).result(context.get_binding)
        YAML.load(erb)
      rescue Errno::ENOENT
        raise if @attempts_left.zero?

        @path = @path.sub(/\#\/?$/, '').sub(/\.json/, '.json.yml')
        @attempts_left -= 1

        retry
      end
      alias_method :payload, :read
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lurker-1.0.0 lib/lurker/json/reader.rb
lurker-0.6.12 lib/lurker/json/reader.rb
lurker-0.6.11 lib/lurker/json/reader.rb
lurker-0.6.10 lib/lurker/json/reader.rb
lurker-0.6.9 lib/lurker/json/reader.rb
lurker-0.6.8 lib/lurker/json/reader.rb
lurker-0.6.7 lib/lurker/json/reader.rb
lurker-0.6.6 lib/lurker/json/reader.rb
lurker-0.6.5 lib/lurker/json/reader.rb
lurker-0.6.4 lib/lurker/json/reader.rb
lurker-0.6.3 lib/lurker/json/reader.rb