Class: Rock::Bundles::Bundle

Inherits:
Object
  • Object
show all
Defined in:
lib/rock/bundles.rb

Overview

Representation of a bundle we found

The bundle's configuration parameters are stored under the 'bundle' key in either config/app.yml or config/bundle.yml

config/app.yml or config/bundle.yml are used to recognize bundles from normal directories. See Bundles.is_bundle_path?.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Bundle

Returns a new instance of Bundle



52
53
54
55
# File 'lib/rock/bundles.rb', line 52

def initialize(path)
    @name = File.basename(path)
    @path = path
end

Instance Attribute Details

#configObject

The bundle's configuration hash. It gets loaded ony if #load_config is called.

Configuration in bundles



41
42
43
# File 'lib/rock/bundles.rb', line 41

def config
  @config
end

#nameObject (readonly)

The bundle name



34
35
36
# File 'lib/rock/bundles.rb', line 34

def name
  @name
end

#pathObject (readonly)

The full path to the bundle



36
37
38
# File 'lib/rock/bundles.rb', line 36

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



57
58
59
60
61
# File 'lib/rock/bundles.rb', line 57

def ==(other)
    return false if !other.kind_of?(Bundle)
    other.name == name &&
        other.path == path
end

#each_dependency(&block) ⇒ Object

Enumerate the names of the bundles on which this bundle depends



82
83
84
# File 'lib/rock/bundles.rb', line 82

def each_dependency(&block)
    load_config['dependencies'].each(&block)
end

#load_configObject

Loads the configuration file, or return an already loaded configuration



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rock/bundles.rb', line 65

def load_config
    if @config
        return config
    end

    if File.file?(bundle_yml = File.join(path, "config", "bundle.yml"))
        base = YAML.load(File.read(bundle_yml))
    elsif File.file?(app_yml = File.join(path, "config", "app.yml"))
        base = YAML.load(File.read(app_yml))
    end
    base ||= Hash.new
    @config = (base['bundle'] || Hash.new)
    @config['dependencies'] ||= Array.new
    config
end

#registered?Boolean

Returns true if this bundle can be found through the ROCK_BUNDLE_PATH or if it must be referred to through its full path

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/rock/bundles.rb', line 45

def registered?
    paths = (ENV['ROCK_BUNDLE_PATH'] || '').split(":")
    paths.any? do |p|
        p == path || path =~ /^#{Regexp.quote(p)}/
    end
end