Class: Npm2Rpm::Metadata
- Inherits:
-
Object
- Object
- Npm2Rpm::Metadata
- Defined in:
- lib/npm2rpm/metadata.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
npmdata is version-specific information.
-
#npmdata ⇒ Object
readonly
npmdata is version-specific information.
-
#version ⇒ Object
readonly
npmdata is version-specific information.
Instance Method Summary collapse
-
#initialize(name, version = nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #method_missing(name, *args) ⇒ Object
- #tarball ⇒ Object
Constructor Details
#initialize(name, version = nil) ⇒ Metadata
Returns a new instance of Metadata.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/npm2rpm/metadata.rb', line 128 def initialize name, version = nil # Get details from central NPM repository # FIXME: Server returns... not quite JSON. = "https://registry.npmjs.org/#{name}" json = Download.new().content # $metadata_json =~ s/\b([^"':\s]+)(:\s+)/"$1"$2/gm; # $metadata_json =~ s/'/"/gm; = JSON.parse json @version = version || ["dist-tags"]["latest"] || abort("Can't determine version") puts "#{name}-#{@version}" @npmdata = ["versions"][@version] || abort("No such version: #{@version.inspect}") @name = ["name"] abort("Name mismatch, want #{name.inspect}, got #{@name.inspect}") unless name == @name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/npm2rpm/metadata.rb', line 148 def method_missing name, *args result = [name.to_s] while args s = args.shift case result when Hash result = result[s.to_s] else result = nil break end end result end |
Instance Attribute Details
#name ⇒ Object (readonly)
npmdata is version-specific information
127 128 129 |
# File 'lib/npm2rpm/metadata.rb', line 127 def name @name end |
#npmdata ⇒ Object (readonly)
npmdata is version-specific information
127 128 129 |
# File 'lib/npm2rpm/metadata.rb', line 127 def npmdata @npmdata end |
#version ⇒ Object (readonly)
npmdata is version-specific information
127 128 129 |
# File 'lib/npm2rpm/metadata.rb', line 127 def version @version end |
Instance Method Details
#tarball ⇒ Object
144 145 146 |
# File 'lib/npm2rpm/metadata.rb', line 144 def tarball url = @npmdata["dist"]["tarball"] end |