Class: EY::Serverside::DependencyManager::Bundler::Lockfile

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard-serverside/dependency_manager/bundler.rb

Constant Summary collapse

METADATA =
'METADATA'.freeze
BUNDLED =
'BUNDLED WITH'.freeze
DEPENDENCIES =
'DEPENDENCIES'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lockfile_contents, default = EY::Serverside::DependencyManager::Bundler.default_version) ⇒ Lockfile

Returns a new instance of Lockfile.


172
173
174
175
176
177
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 172

def initialize(lockfile_contents, default = EY::Serverside::DependencyManager::Bundler.default_version)
  @contents = lockfile_contents
  @default = default
  @default_gem_version = Gem::Version.new(@default)
  parse
end

Instance Attribute Details

#bundler_versionObject (readonly)

Returns the value of attribute bundler_version


166
167
168
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 166

def bundler_version
  @bundler_version
end

Instance Method Details

#any_database_adapter?Boolean

Returns:

  • (Boolean)

192
193
194
195
196
197
198
199
200
201
202
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 192

def any_database_adapter?
  any_ruby_adapter = %w[mysql2 mysql do_mysql pg do_postgres].any? do |type|
    @contents.index(/^\s+#{type}\s\([^\)]+\)$/)
  end

  any_jruby_adapter = %w[mysql postgresql postgres].any? do |type|
    @contents.index(/^\s+jdbc-#{type}\s\([^\)]+\)$/) || @contents.index(/^\s+activerecord-jdbc#{type}-adapter\s\([^\)]+\)$/)
  end

  any_ruby_adapter || any_jruby_adapter
end

#dependencies_sectionObject


238
239
240
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 238

def dependencies_section
  @dependencies_section ||= slice_section(DEPENDENCIES)
end

#fetch_version(operator, version) ⇒ Object


252
253
254
255
256
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 252

def fetch_version(operator, version)
  return version || @default unless operator && version
  req = Gem::Requirement.new(["#{operator} #{version}"])
  req.satisfied_by?(@default_gem_version) ? @default : version
end

#has_ey_config?Boolean

Returns:

  • (Boolean)

179
180
181
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 179

def has_ey_config?
  !!@contents.index(/^\s+ey_config\s\([^\)]+\)$/)
end

#parseObject


208
209
210
211
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 208

def parse
  @bundler_version =  || parse_from_bundled_with || parse_from_dependencies
  raise("Malformed or pre bundler-1.0.0 Gemfile.lock: #{@contents[0,50]}...") unless @bundler_version
end

#parse_from_bundled_withObject


230
231
232
233
234
235
236
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 230

def parse_from_bundled_with
  section = slice_section(BUNDLED)
  return if section.empty?

  result = section.scan(/^#{BUNDLED}\s*(.*)$/).first
  result ? result.first : @default
end

#parse_from_dependenciesObject


242
243
244
245
246
247
248
249
250
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 242

def parse_from_dependencies
  section = dependencies_section
  return if section.empty?

  result = scan_gem('bundler', section)
  bundler_version = result ? result.last : nil
  version_qualifier = result ? result.first : nil
  @bundler_version = fetch_version(version_qualifier, bundler_version)
end

#parse_from_metadataObject


222
223
224
225
226
227
228
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 222

def 
  section = slice_section(METADATA)
  return if section.empty?

  result = section.scan(/^\s*version:\s*(.*)$/).first
  result ? result.first : @default
end

#rails_versionObject


183
184
185
186
187
188
189
190
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 183

def rails_version
  section = dependencies_section
  if section.empty?
    return nil
  end
  result = scan_gem('rails', section)
  result ? result.last : nil
end

#scan_gem(gem, dep_section) ⇒ Object


258
259
260
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 258

def scan_gem(gem, dep_section)
  dep_section.scan(/^\s*#{Regexp.escape(gem)}\s*\((>?=|~>)\s*([^,\)]+)/).first
end

#slice_section(header) ⇒ Object


213
214
215
216
217
218
219
220
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 213

def slice_section(header)
  if start = @contents.index(/^#{header}/)
    finish = @contents.index(/(^\S|\Z)/, start + header.length)
    @contents.slice(start..finish)
  else
    ""
  end
end

#uses_sqlite3?Boolean

Returns:

  • (Boolean)

204
205
206
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 204

def uses_sqlite3?
  !any_database_adapter? && @contents.index(/^\s+sqlite3\s\([^\)]+\)$/)
end