Module: FastlyCTL::Utils
- Defined in:
- lib/fastlyctl/utils.rb
Class Method Summary collapse
- .diff_generated(v1, v2) ⇒ Object
- .diff_versions(v1, v2) ⇒ Object
- .filter_vnd(haystack, needle) ⇒ Object
- .get_diff(old_vcl, new_vcl) ⇒ Object
- .open_app_path(path) ⇒ Object
- .open_service(id) ⇒ Object
- .parse_directory(path = false) ⇒ Object
- .parse_name(path = false) ⇒ Object
- .percent_encode(string) ⇒ Object
Class Method Details
.diff_generated(v1, v2) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/fastlyctl/utils.rb', line 40 def self.diff_generated(v1,v2) diff = "" diff << "\n" + self.get_diff(v1["content"], v2["content"]) return diff end |
.diff_versions(v1, v2) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fastlyctl/utils.rb', line 48 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 |
.filter_vnd(haystack, needle) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fastlyctl/utils.rb', line 81 def self.filter_vnd(haystack,needle) results = [] haystack.each do |i| next unless i["type"] == needle results.push(i) end return results end |
.get_diff(old_vcl, new_vcl) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/fastlyctl/utils.rb', line 31 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_app_path(path) ⇒ Object
7 8 9 |
# File 'lib/fastlyctl/utils.rb', line 7 def self.open_app_path(path) Launchy.open(FastlyCTL::FASTLY_APP + path) 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
11 12 13 14 15 16 17 18 19 |
# File 'lib/fastlyctl/utils.rb', line 11 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
21 22 23 24 25 26 27 28 29 |
# File 'lib/fastlyctl/utils.rb', line 21 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 |
.percent_encode(string) ⇒ Object
76 77 78 79 |
# File 'lib/fastlyctl/utils.rb', line 76 def self.percent_encode(string) # CGI.escape replace whitespace to "+" which is "%20" in a percent-encoding manner CGI.escape(string).gsub('+', '%20') end |