Class: Diligent::List
- Inherits:
-
Object
- Object
- Diligent::List
- Includes:
- ERB::Util
- Defined in:
- lib/diligent/list.rb
Instance Attribute Summary collapse
-
#project_name ⇒ String
The name of the project we're reading, currently assumed to be the directory name.
-
#specs ⇒ Bundler::SpecSet
Dependency info as generated by
Bundler.load.specs
.
Class Method Summary collapse
-
.load ⇒ Hash
Initialize and return gem info in a single step.
Instance Method Summary collapse
-
#as_csv(filename = nil) ⇒ String
Output dependency info as CSV.
-
#as_hash ⇒ Hash
Output dependency info as a hash.
-
#as_html(filename = nil) ⇒ String
Output dependency info as HTML.
-
#as_json(filename = nil) ⇒ String
Output dependency info as JSON.
-
#initialize ⇒ List
constructor
A new instance of List.
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
29 30 31 32 33 |
# File 'lib/diligent/list.rb', line 29 def initialize # TODO Optionally point at a different path? @project_name = File.split(FileUtils.getwd).last @specs = Bundler.load.specs end |
Instance Attribute Details
#project_name ⇒ String
Returns the name of the project we're reading, currently assumed to be the directory name.
12 13 14 |
# File 'lib/diligent/list.rb', line 12 def project_name @project_name end |
#specs ⇒ Bundler::SpecSet
Returns Dependency info as generated by
Bundler.load.specs
.
17 18 19 |
# File 'lib/diligent/list.rb', line 17 def specs @specs end |
Class Method Details
.load ⇒ Hash
Initialize and return gem info in a single step. May be deprecated as it seems to be of limited use.
24 25 26 |
# File 'lib/diligent/list.rb', line 24 def load self.new.as_hash end |
Instance Method Details
#as_csv(filename = nil) ⇒ String
Output dependency info as CSV.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/diligent/list.rb', line 64 def as_csv(filename = nil) as_array = as_hash.inject([]) do |arr, gem_info| row = [] row << gem_info.first gem_info.last.inject(row) do |r, i| r << i.last end arr << row end csv = CSV.generate do |csv| csv << %w{ Gem Version Author Summary Description License Homepage } as_array.each { |row| csv << row } end write_to_file filename, csv end |
#as_hash ⇒ Hash
Output dependency info as a hash.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/diligent/list.rb', line 37 def as_hash @specs.inject({}) do |hash, spec| hash[spec.name] = { 'version' => spec.version.to_s, 'author' => spec., 'summary' => spec.summary, 'description' => spec.description, 'license' => spec.license, 'homepage' => spec.homepage } hash end end |
#as_html(filename = nil) ⇒ String
Output dependency info as HTML.
85 86 87 88 89 90 91 |
# File 'lib/diligent/list.rb', line 85 def as_html(filename = nil) list = as_hash template_path = File.join(File.dirname(__FILE__), '../../templates/list.html.erb') html = ERB.new(File.read(template_path)).result(binding) write_to_file filename, html end |
#as_json(filename = nil) ⇒ String
Output dependency info as JSON. A JSON string is returned by the method even if a filename is specified.
56 57 58 59 |
# File 'lib/diligent/list.rb', line 56 def as_json(filename = nil) json = as_hash.to_json write_to_file filename, json end |