Module: FastlyCTL::Utils
- Defined in:
- lib/fastlyctl/utils.rb
Class Method Summary collapse
- .diff_generated(v1, v2) ⇒ Object
- .diff_versions(v1, v2) ⇒ Object
- .get_diff(old_vcl, new_vcl) ⇒ Object
- .open_service(id) ⇒ Object
- .parse_directory(path = false) ⇒ Object
- .parse_name(path = false) ⇒ Object
Class Method Details
.diff_generated(v1, v2) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/fastlyctl/utils.rb', line 36 def self.diff_generated(v1,v2) diff = "" diff << "\n" + self.get_diff(v1["content"], v2["content"]) return diff end |
.diff_versions(v1, v2) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fastlyctl/utils.rb', line 44 def self.diff_versions(v1,v2) diff = "" v1 ||= Array.new v2 ||= Array.new v1.each do |vcl1| v2_content = false v2.each do |vcl2| v2_content = vcl2["content"] if (vcl1["name"] == vcl2["name"]) if (v2_content) vcl2["matched"] = true break end end v2_content = "" unless v2_content diff << "\n" + self.get_diff(vcl1["content"], v2_content) end v2.each do |vcl| diff << "\n" + self.get_diff("", vcl["content"]) if !(vcl.has_key? "matched") end return diff end |
.get_diff(old_vcl, new_vcl) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/fastlyctl/utils.rb', line 27 def self.get_diff(old_vcl,new_vcl) = { include_diff_info: true, diff: ["-E", "-p"], context: 3 } return Diffy::Diff.new(old_vcl, new_vcl, ).to_s(:color) end |
.open_service(id) ⇒ Object
3 4 5 |
# File 'lib/fastlyctl/utils.rb', line 3 def self.open_service(id) Launchy.open(FastlyCTL::FASTLY_APP + FastlyCTL::TANGO_PATH + id) end |
.parse_directory(path = false) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/fastlyctl/utils.rb', line 7 def self.parse_directory(path=false) directory = Dir.pwd unless path directory = path if path id = directory.match(/.* \- ([^\-]*)$/i) id = id == nil ? false : id.captures[0] return id end |
.parse_name(path = false) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/fastlyctl/utils.rb', line 17 def self.parse_name(path=false) directory = Dir.pwd unless path directory = path if path name = directory.match(/(.*) \- [^\-]*$/i) name = name == nil ? false : name.captures[0] return name end |