Sha256: cb34bf825c8567455c0580d0fcd000f841b076f180e02b2bb2aa9f9d17b4c66d

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

module PowerStencil
  module Project

    module Config

      include PowerStencil::Project::Paths

      attr_reader :plugin_priority_count

      def load_project_specific_config
        # Optional config files should have less priority than the command line layer
        add_optional_config_layer project_versioned_config_file, 'versioned project config file', 70
        add_optional_config_layer project_personal_config_file, 'personal project config file', 900
      end

      def add_plugin_config(plugin_name)
        yaml_file = plugin_config_specific_file plugin_name
        priority = if priority.nil?
                     200
                   else
                     plugin_priority_count + 1
                   end

        add_optional_config_layer yaml_file, "'#{plugin_name}' plugin specific config", priority
        @plugin_priority_count ||= 0
        @plugin_priority_count += 1
      end

      private

      def add_optional_config_layer(yaml_file, layer_name, layer_priority)
        if File.readable? yaml_file
          logger.debug "Loading #{layer_name}: '#{yaml_file}'..."
          begin
            new_config_layer = SuperStack::Layer.new.load yaml_file
            new_config_layer.name = layer_name
            new_config_layer.priority = layer_priority
            config << new_config_layer
            new_config_layer
          rescue => e
            logger.error "The #{layer_name} '#{yaml_file}' is invalid and has been ignored !"
            logger.debug PowerStencil::Error.report_error(e)
            false
          end
        else
          logger.debug "No #{layer_name} found."
          false
        end
      end

    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
power_stencil-0.3.3 lib/power_stencil/project/config.rb
power_stencil-0.3.2 lib/power_stencil/project/config.rb
power_stencil-0.3.1 lib/power_stencil/project/config.rb
power_stencil-0.3.0 lib/power_stencil/project/config.rb