Class: Bibliothecary::Parsers::Bower
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::Bower
- Defined in:
- lib/bibliothecary/parsers/bower.rb
Constant Summary collapse
- PLATFORM_NAME =
'bower'
Class Method Summary collapse
- .analyse(folder_path, file_list) ⇒ Object
- .map_dependencies(hash, key, type) ⇒ Object
- .parse(filename, file_contents) ⇒ Object
- .parse_manifest(manifest) ⇒ Object
Class Method Details
.analyse(folder_path, file_list) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bibliothecary/parsers/bower.rb', line 17 def self.analyse(folder_path, file_list) path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^bower\.json$/) } return unless path manifest = JSON.parse File.open(path).read { platform: PLATFORM_NAME, path: path, dependencies: parse_manifest(manifest) } end |
.map_dependencies(hash, key, type) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/bibliothecary/parsers/bower.rb', line 35 def self.map_dependencies(hash, key, type) hash.fetch(key,[]).map do |name, requirement| { name: name, requirement: requirement, type: type } end end |
.parse(filename, file_contents) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/bibliothecary/parsers/bower.rb', line 8 def self.parse(filename, file_contents) json = JSON.parse(file_contents) if filename.match(/^bower\.json$/) parse_manifest(json) else [] end end |
.parse_manifest(manifest) ⇒ Object
30 31 32 33 |
# File 'lib/bibliothecary/parsers/bower.rb', line 30 def self.parse_manifest(manifest) map_dependencies(manifest, 'dependencies', 'runtime') + map_dependencies(manifest, 'devDependencies', 'development') end |