Class: RestoreBundledWith::Lock
- Inherits:
-
Object
- Object
- RestoreBundledWith::Lock
- Defined in:
- lib/restore_bundled_with/lock.rb
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 ⇒ Object
readonly
Returns the value of attribute body.
Class Method Summary collapse
- .insert(text, section) ⇒ Object
- .restore(data, lockfile = Repository::LOCK_FILE, ref = Repository::REF, git_path = Repository::GIT_PATH, git_options = Repository::GIT_OPTIONS, new_line = Repository::NEW_LINE) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#delete_bundled_with ⇒ Object
“nnBUNDLED WITHn 1.10.4n” => “n”.
-
#initialize(text) ⇒ Lock
constructor
A new instance of Lock.
- #pick ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(text) ⇒ Lock
Returns a new instance of Lock.
32 33 34 |
# File 'lib/restore_bundled_with/lock.rb', line 32 def initialize(text) @body = text end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/restore_bundled_with/lock.rb', line 3 def body @body end |
Class Method Details
.insert(text, section) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/restore_bundled_with/lock.rb', line 7 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) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/restore_bundled_with/lock.rb', line 15 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) ⇒ Object
54 55 56 |
# File 'lib/restore_bundled_with/lock.rb', line 54 def ==(other) body == other.body end |
#delete_bundled_with ⇒ Object
“nnBUNDLED WITHn 1.10.4n” => “n”
37 38 39 |
# File 'lib/restore_bundled_with/lock.rb', line 37 def delete_bundled_with self.class.new(body.sub(REGEX_BUNDLED_WITH) { '' }) end |
#pick ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/restore_bundled_with/lock.rb', line 41 def pick match = REGEX_BUNDLED_WITH.match(body) if match match[:pick] else '' end end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/restore_bundled_with/lock.rb', line 50 def to_s body end |