Class: Npm2Rpm::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/npm2rpm/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.
  @metaurl = "https://registry.npmjs.org/#{name}"
  
  json = Download.new(@metaurl).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

#nameObject (readonly)

npmdata is version-specific information



127
128
129
# File 'lib/npm2rpm/metadata.rb', line 127

def name
  @name
end

#npmdataObject (readonly)

npmdata is version-specific information



127
128
129
# File 'lib/npm2rpm/metadata.rb', line 127

def npmdata
  @npmdata
end

#versionObject (readonly)

npmdata is version-specific information



127
128
129
# File 'lib/npm2rpm/metadata.rb', line 127

def version
  @version
end

Instance Method Details

#tarballObject



144
145
146
# File 'lib/npm2rpm/metadata.rb', line 144

def tarball
  url = @npmdata["dist"]["tarball"]
end