Class: Shomen::Metadata
- Inherits:
-
Object
- Object
- Shomen::Metadata
- Includes:
- Enumerable
- Defined in:
- lib/shomen/metadata.rb
Overview
Encapsulate metadata, which preferably comes from a .ruby file, but can fallback to a gemspec.
Constant Summary collapse
- PWD =
Present working directoty.
Dir.pwd
- GEMSPEC_PATTERN =
Glob pattern for looking up gemspec.
'{.gemspec,*.gemspec}'
Instance Method Summary collapse
- #[](name) ⇒ Object
- #dotruby ⇒ Object
- #each(&blk) ⇒ Object
- #gemspec ⇒ Object
-
#initialize ⇒ Metadata
constructor
A new instance of Metadata.
- #size ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Metadata
Returns a new instance of Metadata.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/shomen/metadata.rb', line 18 def initialize @data = ( data = {} if dotruby data.merge!(YAML.load_file(dotruby)) elsif gemspec # prefereably use dotruby library to convert, # but wait until it's more mainstream require 'rubygems/specification' spec = ::Gem::Specification.load(gemspec) data['name'] = spec.name, data['title'] = spec.name.capitalize, data['version'] = spec.version.to_s, data['authors'] = [spec.], data['summary'] = spec.summary, data['description'] = spec.description, data['resources'] = {'homepage' => spec.homepage} else # TODO: Raise error instead ? data['name'] = File.basename(Dir.pwd) end data['path'] = '(metadata)' data['markup'] = 'rdoc' # FIXME data ) end |
Instance Method Details
#[](name) ⇒ Object
60 61 62 |
# File 'lib/shomen/metadata.rb', line 60 def [](name) @data[name] end |
#dotruby ⇒ Object
46 47 48 49 50 |
# File 'lib/shomen/metadata.rb', line 46 def dotruby file = File.join(PWD, '.ruby') return nil unless File.exist?(file) file end |
#each(&blk) ⇒ Object
70 71 72 |
# File 'lib/shomen/metadata.rb', line 70 def each(&blk) @data.each(&blk) end |
#gemspec ⇒ Object
53 54 55 56 57 |
# File 'lib/shomen/metadata.rb', line 53 def gemspec file = Dir[File.join(PWD, GEMSPEC_PATTERN)].first return nil unless file && File.exist?(file) file end |
#size ⇒ Object
65 66 67 |
# File 'lib/shomen/metadata.rb', line 65 def size @data.size end |
#to_h ⇒ Object
75 76 77 |
# File 'lib/shomen/metadata.rb', line 75 def to_h @data end |