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

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

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.


146
147
148
149
150
151
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 146

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


144
145
146
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 144

def bundler_version
  @bundler_version
end

Instance Method Details

#any_database_adapter?Boolean

Returns:

  • (Boolean)

166
167
168
169
170
171
172
173
174
175
176
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 166

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


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

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

#fetch_version(operator, version) ⇒ Object


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

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)

153
154
155
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 153

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

#parseObject


182
183
184
185
186
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 182

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

#parse_from_dependenciesObject


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

def parse_from_dependencies
  section = dependencies_section
  if section.empty?
    return nil
  end

  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


197
198
199
200
201
202
203
204
205
206
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 197

def 
  section = slice_section('METADATA')

  if section.empty?
    return nil
  end

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

#rails_versionObject


157
158
159
160
161
162
163
164
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 157

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


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

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

#slice_section(header) ⇒ Object


188
189
190
191
192
193
194
195
# File 'lib/engineyard-serverside/dependency_manager/bundler.rb', line 188

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)

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

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