Sha256: d7e94756e1f4b24a836a55e4ae287e00ac975bb6708cd2c48c7ffbcae6c44fd3

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

module Hieracles
  module Registry
  	extend self

  	def farms(config)
  		Dir.glob(format(config.classpath, '*')).sort.map do |f|
        sub = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
        f.sub(sub, "\\1")
      end
  	end

    def nodes(config)
      Dir.glob(File.join(config.encpath, '*.yaml')).sort.map do |f|
        File.basename(f, '.yaml')
      end
    end

    def modules(config)
      Dir.glob(File.join(config.modulepath, '*')).sort.map do |f|
        File.basename(f)
      end
    end

    def reload_nodes()
      @_nodes_parameters = {}
      @_nodes_modules = {}
    end

    def nodes_parameters(config, env = 'production')
      @_nodes_parameters ||= {}
      @_nodes_parameters[env] ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.reduce({}) do |a, f|
        fqdn = File.basename(f, '.yaml')
        a[fqdn] = YAML.load_file(f)['parameters']
        a
      end
    end

    def nodes_modules(config, env = 'production')
      @_nodes_modules ||= {}
      @_nodes_modules[env] ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.reduce({}) do |a, f|
        YAML.load_file(f)['classes'].each do |cl|

        end
        fqdn = File.basename(f, '.yaml')
        a[fqdn] = YAML.load_file(f)['parameters']
        a
      end
    end

    def farms_counted(config, env = 'production', reload = false)
      reload_nodes if reload
      Dir.glob(format(config.classpath, '*')).sort.reduce({}) do |a, f|
        sub = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
        name = f.sub(sub, "\\1")
        a[name] = nodes_parameters(config, env).select { |k, v| v['farm'] == name }.length
        a
      end
    end

    def modules_counted(config, env = 'production', reload = false)
      reload_nodes if reload
      Dir.glob(File.join(config.modulepath, '*')).sort.reduce({}) do |acc, mod|
        acc
      end
    end

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hieracles-0.3.6 lib/hieracles/registry.rb