Class: DiffuxCIUtils
- Inherits:
-
Object
- Object
- DiffuxCIUtils
- Defined in:
- lib/diffux_ci_utils.rb
Class Method Summary collapse
- .config ⇒ Object
- .config_from_file ⇒ Object
- .construct_url(absolute_path, params = {}) ⇒ Object
- .current_snapshots ⇒ Object
- .normalize_description(description) ⇒ Object
- .path_to(description, viewport_name, file_name) ⇒ Object
Class Method Details
.config ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/diffux_ci_utils.rb', line 7 def self.config @@config ||= { 'snapshots_folder' => './snapshots', 'source_files' => [], 'stylesheets' => [], 'port' => 4567, 'driver' => :firefox, 'viewports' => { 'large' => { 'width' => 1024, 'height' => 768 }, 'medium' => { 'width' => 640, 'height' => 888 }, 'small' => { 'width' => 320, 'height' => 444 } } }.merge(config_from_file) end |
.config_from_file ⇒ Object
31 32 33 34 |
# File 'lib/diffux_ci_utils.rb', line 31 def self.config_from_file config_file_name = ENV['DIFFUX_CI_CONFIG_FILE'] || '.diffux_ci.yaml' YAML.load(ERB.new(File.read(config_file_name)).result) end |
.construct_url(absolute_path, params = {}) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/diffux_ci_utils.rb', line 49 def self.construct_url(absolute_path, params = {}) query = URI.encode_www_form(params) unless params.empty? URI::HTTP.build(host: 'localhost', port: config['port'], path: absolute_path, query: query).to_s end |
.current_snapshots ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/diffux_ci_utils.rb', line 58 def self.current_snapshots prepare_file = lambda do |file| = File.('..', file) description_dir = File.('..', ) { description: Base64.decode64(File.basename(description_dir)), viewport: File.basename().sub('@', ''), file: file } end snapshots_folder = DiffuxCIUtils.config['snapshots_folder'] diff_files = Dir.glob("#{snapshots_folder}/**/diff.png") baselines = Dir.glob("#{snapshots_folder}/**/baseline.png") { diffs: diff_files.map(&prepare_file), baselines: baselines.map(&prepare_file) } end |
.normalize_description(description) ⇒ Object
36 37 38 |
# File 'lib/diffux_ci_utils.rb', line 36 def self.normalize_description(description) Base64.encode64(description).strip end |
.path_to(description, viewport_name, file_name) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/diffux_ci_utils.rb', line 40 def self.path_to(description, , file_name) File.join( config['snapshots_folder'], normalize_description(description), "@#{}", file_name ) end |