class RestoreBundledWith::Lock

The lock file

Constants

REGEX_BUNDLED_WITH

@!attribute [r] body

@return [String] file body

Attributes

body[R]

Public Class Methods

insert(text, section) click to toggle source

@param text [String] base lock file @param section [String] appending section

@return [Lock] the lock file instance

# File lib/restore_bundled_with/lock.rb, line 14
def self.insert(text, section)
  if section && !section.empty?
    new(text + section)
  else
    new(text)
  end
end
new(text) click to toggle source

@param text [String] the lock file contents

@return [Lock] the lock file instance

# File lib/restore_bundled_with/lock.rb, line 50
def initialize(text)
  @body = text
end
restore( data, lockfile = Repository::LOCK_FILE, ref = Repository::REF, git_path = Repository::GIT_PATH, git_options = Repository::GIT_OPTIONS, new_line = Repository::NEW_LINE ) click to toggle source

@param data [String] before restore @param lockfile [String] file name @param ref [String] git ref @param git_path [String] git repository path @param git_options [Hash] ruby-git options @param new_line [String] new line

@return [Lock] the lock file instance

# File lib/restore_bundled_with/lock.rb, line 30
def self.restore(
  data,
  lockfile = Repository::LOCK_FILE,
  ref = Repository::REF,
  git_path = Repository::GIT_PATH,
  git_options = Repository::GIT_OPTIONS,
  new_line = Repository::NEW_LINE
)
  trimmed = new(data).delete_bundled_with
  lock_file_data = Repository
                   .new(git_path, git_options)
                   .fetch_file(lockfile, ref, new_line)
  section = new(lock_file_data)
            .pick
  insert(trimmed.body, section)
end

Public Instance Methods

==(other) click to toggle source

@param [#body] other compare body

@return [Boolean] true if file body is same

# File lib/restore_bundled_with/lock.rb, line 80
def ==(other)
  body == other.body
end
delete_bundled_with() click to toggle source

@example delete bundled with

"\n\nBUNDLED WITH\n   1.10.4\n" => "\n"

@return [Lock] new lock file instance which is deleted bundled with

# File lib/restore_bundled_with/lock.rb, line 58
def delete_bundled_with
  self.class.new(body.sub(REGEX_BUNDLED_WITH) { '' })
end
pick() click to toggle source

@return [String] pick target section

# File lib/restore_bundled_with/lock.rb, line 63
def pick
  match = REGEX_BUNDLED_WITH.match(body)
  if match
    match[:pick]
  else
    ''
  end
end
to_s() click to toggle source

@return [String] the lock file contents

# File lib/restore_bundled_with/lock.rb, line 73
def to_s
  body
end