Class: Licensed::Source::Bower

Inherits:
Object
  • Object
show all
Defined in:
lib/licensed/source/bower.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Bower

Returns a new instance of Bower.



11
12
13
# File 'lib/licensed/source/bower.rb', line 11

def initialize(config)
  @config = config
end

Class Method Details

.typeObject



7
8
9
# File 'lib/licensed/source/bower.rb', line 7

def self.type
  "bower"
end

Instance Method Details

#bower_configObject

Returns a parsed “.bowerrc” configuration, or an empty hash if not found



36
37
38
39
40
41
# File 'lib/licensed/source/bower.rb', line 36

def bower_config
  @bower_config ||= begin
    path = @config.pwd.join(".bowerrc")
    path.exist? ? JSON.parse(path.read) : {}
  end
end

#bower_pathObject

Returns the expected path to bower components. Note this does not validate that the returned path is valid



45
46
47
48
# File 'lib/licensed/source/bower.rb', line 45

def bower_path
  pwd = bower_config["cwd"] ? Pathname.new(bower_config["cwd"]).expand_path : @config.pwd
  pwd.join bower_config["directory"] || "bower_components"
end

#dependenciesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/licensed/source/bower.rb', line 21

def dependencies
  @dependencies ||= Dir.glob(bower_path.join("*/.bower.json")).map do |file|
    package = JSON.parse(File.read(file))
    path = bower_path.join(file).dirname.to_path
    Dependency.new(path, {
      "type"     => Bower.type,
      "name"     => package["name"],
      "version"  => package["version"] || package["_release"],
      "summary"  => package["description"],
      "homepage" => package["homepage"]
    })
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/licensed/source/bower.rb', line 15

def enabled?
  [@config.pwd.join(".bowerrc"), @config.pwd.join("bower.json")].any? do |path|
    File.exist?(path)
  end
end