Class: RestoreBundledWith::Lock
- Inherits:
-
Object
- Object
- RestoreBundledWith::Lock
- Defined in:
- lib/restore_bundled_with/lock.rb
Overview
The lock file
Constant Summary collapse
- REGEX_BUNDLED_WITH =
/^(?<pick>(?:\r\n|\r|\n)^BUNDLED WITH.*(?:\r\n|\r|\n).+(?:\r\n|\r|\n))/
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
File body.
Class Method Summary collapse
-
.insert(text, section) ⇒ Lock
The lock file instance.
-
.restore(data, lockfile = Repository::LOCK_FILE, ref = Repository::REF, git_path = Repository::GIT_PATH, git_options = Repository::GIT_OPTIONS, new_line = Repository::NEW_LINE) ⇒ Lock
The lock file instance.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if file body is same.
-
#delete_bundled_with ⇒ Lock
New lock file instance which is deleted bundled with.
-
#initialize(text) ⇒ Lock
constructor
The lock file instance.
-
#pick ⇒ String
Pick target section.
-
#to_s ⇒ String
The lock file contents.
Constructor Details
#initialize(text) ⇒ Lock
Returns the lock file instance.
50 51 52 |
# File 'lib/restore_bundled_with/lock.rb', line 50 def initialize(text) @body = text end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns file body.
8 9 10 |
# File 'lib/restore_bundled_with/lock.rb', line 8 def body @body end |
Class Method Details
.insert(text, section) ⇒ Lock
Returns the lock file instance.
14 15 16 17 18 19 20 |
# 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 |
.restore(data, lockfile = Repository::LOCK_FILE, ref = Repository::REF, git_path = Repository::GIT_PATH, git_options = Repository::GIT_OPTIONS, new_line = Repository::NEW_LINE) ⇒ Lock
Returns the lock file instance.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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, = Repository::GIT_OPTIONS, new_line = Repository::NEW_LINE ) trimmed = new(data).delete_bundled_with lock_file_data = Repository .new(git_path, ) .fetch_file(lockfile, ref, new_line) section = new(lock_file_data) .pick insert(trimmed.body, section) end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if file body is same.
80 81 82 |
# File 'lib/restore_bundled_with/lock.rb', line 80 def ==(other) body == other.body end |
#delete_bundled_with ⇒ Lock
Returns new lock file instance which is deleted bundled with.
58 59 60 |
# File 'lib/restore_bundled_with/lock.rb', line 58 def delete_bundled_with self.class.new(body.sub(REGEX_BUNDLED_WITH) { '' }) end |
#pick ⇒ String
Returns pick target section.
63 64 65 66 67 68 69 70 |
# 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 ⇒ String
Returns the lock file contents.
73 74 75 |
# File 'lib/restore_bundled_with/lock.rb', line 73 def to_s body end |