Sha256: 47407591c9cb55db71c173de237e28471a426becbae195f1e11dbdd65d5800c9

Contents?: true

Size: 710 Bytes

Versions: 4

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

module Esse
  class IndexMapping
    FILENAMES = %w[mapping mappings].freeze

    def initialize(body: {}, paths: [], filenames: FILENAMES)
      @paths = Array(paths)
      @filenames = Array(filenames)
      @mappings = body
    end

    # This method will be overwrited when passing a block during the
    # mapping defination
    def as_json
      return @mappings unless @mappings.empty?

      from_template || @mappings
    end

    def body
      as_json
    end

    def empty?
      body.empty?
    end

    protected

    def from_template
      return if @paths.empty?

      loader = Esse::TemplateLoader.new(@paths)
      loader.read(*@filenames)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
esse-0.0.5 lib/esse/index_mapping.rb
esse-0.0.4 lib/esse/index_mapping.rb
esse-0.0.3 lib/esse/index_mapping.rb
esse-0.0.2 lib/esse/index_mapping.rb