Class: Autoproj::PackageManagers::BundlerManager::GemEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/autoproj/package_managers/bundler_manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



462
463
464
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 462

def name
  @name
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



462
463
464
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 462

def options
  @options
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



462
463
464
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 462

def version
  @version
end

Class Method Details

.parse(object) ⇒ Object



463
464
465
466
467
468
469
470
471
472
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 463

def self.parse(object)
    if object.respond_to?(:to_str)
        parse_from_string(object)
    elsif object.respond_to?(:to_hash)
        parse_from_hash(object)
    else
        raise ArgumentError,
              "expected #{object} to either be a string or a map"
    end
end

.parse_from_hash(hash) ⇒ Object

Parse an option hash into a GemEntry



491
492
493
494
495
496
497
498
499
500
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 491

def self.parse_from_hash(hash)
    hash = hash.dup
    unless (name = hash.delete("name"))
        raise ArgumentError,
              "expected gem entry #{hash} to have at least a 'name' key"
    end

    version = hash.delete("version")
    GemEntry.new(name, version, hash)
end

.parse_from_string(entry) ⇒ (String,String), (String,nil)

Parse an osdep entry string into a gem name and gem version

The ‘gem’ entries in the osdep files can contain a version specification. This method parses the two parts and return them

Parameters:

  • entry (String)

    the osdep entry

Returns:

  • ((String,String), (String,nil))

    the gem name, and an optional version specification



482
483
484
485
486
487
488
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 482

def self.parse_from_string(entry)
    if entry =~ /^([^><=~]*)([><=~]+.*)$/
        GemEntry.new($1.strip, $2.strip, {})
    else
        GemEntry.new(entry, nil, {})
    end
end

Instance Method Details

#to_gemfile_lineObject



502
503
504
505
506
507
508
509
510
# File 'lib/autoproj/package_managers/bundler_manager.rb', line 502

def to_gemfile_line
    options_s = options.map { |k, v| "#{k}: \"#{v}\"" }.join(", ")
    entries = [
        "\"#{name}\"",
        ("\"#{version}\"" if version),
        (options_s unless options_s.empty?)
    ].compact
    "gem #{entries.join(', ')}"
end