Class: Bundix::Source

Inherits:
Struct
  • Object
show all
Defined in:
lib/bundix/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fetcherObject

Returns the value of attribute fetcher

Returns:

  • (Object)

    the current value of fetcher



126
127
128
# File 'lib/bundix/source.rb', line 126

def fetcher
  @fetcher
end

#specObject

Returns the value of attribute spec

Returns:

  • (Object)

    the current value of spec



126
127
128
# File 'lib/bundix/source.rb', line 126

def spec
  @spec
end

Instance Method Details

#convertObject



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/bundix/source.rb', line 127

def convert
  case spec.source
  when Bundler::Source::Rubygems
    convert_rubygems
  when Bundler::Source::Git
    convert_git
  when Bundler::Source::Path
    convert_path
  else
    pp spec
    fail 'unkown bundler source'
  end
end

#convert_gitObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/bundix/source.rb', line 160

def convert_git
  revision = spec.source.options.fetch('revision')
  uri = spec.source.options.fetch('uri')
  submodules = !!spec.source.submodules
  output = fetcher.nix_prefetch_git(uri, revision, submodules: submodules)
  # FIXME: this is a hack, we should separate $stdout/$stderr in the sh call
  hash = JSON.parse(output[/({[^}]+})\s*\z/m])['sha256']
  fail "couldn't fetch hash for #{spec.full_name}" unless hash
  puts "#{hash} => #{uri}" if $VERBOSE

  { type: 'git',
    url: uri.to_s,
    rev: revision,
    sha256: hash,
    fetchSubmodules: submodules }
end

#convert_pathObject



141
142
143
144
145
146
# File 'lib/bundix/source.rb', line 141

def convert_path
  {
    type: "path",
    path: spec.source.path
  }
end

#convert_rubygemsObject



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/bundix/source.rb', line 148

def convert_rubygems
  remotes = spec.source.remotes.map{|remote| remote.to_s.sub(/\/+$/, '') }
  hash = fetcher.fetch_local_hash(spec)
  remote, hash = fetcher.fetch_remotes_hash(spec, remotes) unless hash
  fail "couldn't fetch hash for #{spec.full_name}" unless hash
  puts "#{hash} => #{spec.full_name}.gem" if $VERBOSE

  { type: 'gem',
    remotes: (remote ? [remote] : remotes),
    sha256: hash }
end