Sha256: a522de9aabb825fa9ad7824911841af684cd37603d64b43f539e18b5a50b1eb6

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Riddle
  class Configuration
    class Index < Riddle::Configuration::Section
      include Riddle::Configuration::IndexSettings

      def self.settings
        Riddle::Configuration::IndexSettings.settings + [:source]
      end

      attr_accessor :parent, :sources

      def initialize(name, *sources)
        @name                     = name
        @sources                  = sources

        initialize_settings
      end

      def source
        @sources.collect { |s| s.name }
      end

      def render
        raise ConfigurationError, "#{@name} #{@sources.inspect} #{@path} #{@parent}" unless valid?

        inherited_name = "#{name}"
        inherited_name << " : #{parent}" if parent
        (
          @sources.collect { |s| s.render } +
          ["index #{inherited_name}", "{"] +
          settings_body +
          ["}", ""]
        ).join("\n")
      end

      def valid?
        (!@name.nil?) && (!( @sources.length == 0 || @path.nil? ) || !@parent.nil?)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
riddle-2.3.1 lib/riddle/configuration/index.rb
riddle-2.3.0 lib/riddle/configuration/index.rb
riddle-2.2.2 lib/riddle/configuration/index.rb
riddle-2.2.1 lib/riddle/configuration/index.rb