Class: CypressViewportUpdater::ViewportPresetJsFile
- Inherits:
-
ExistingGithubFile
- Object
- ExistingGithubFile
- CypressViewportUpdater::ViewportPresetJsFile
- Defined in:
- app/sidekiq/cypress_viewport_updater/viewport_preset_js_file.rb
Instance Attribute Summary
Attributes inherited from ExistingGithubFile
#github_path, #name, #raw_content, #sha, #updated_content
Instance Method Summary collapse
- #create_viewport_presets(line:, viewports:) ⇒ Object private
-
#initialize ⇒ ViewportPresetJsFile
constructor
A new instance of ViewportPresetJsFile.
- #update(viewports:) ⇒ Object
Constructor Details
#initialize ⇒ ViewportPresetJsFile
Returns a new instance of ViewportPresetJsFile.
5 6 7 8 |
# File 'app/sidekiq/cypress_viewport_updater/viewport_preset_js_file.rb', line 5 def initialize super(github_path: 'src/platform/testing/e2e/cypress/support/commands/viewportPreset.js', name: 'viewportPreset.js') end |
Instance Method Details
#create_viewport_presets(line:, viewports:) ⇒ Object (private)
32 33 34 35 36 37 38 39 40 41 |
# File 'app/sidekiq/cypress_viewport_updater/viewport_preset_js_file.rb', line 32 def (line:, viewports:) = /(mobile|tablet|desktop)/.match(line)[0].to_sym .send().each do || rank = .rank width = .width height = .height yield(" 'va-top-#{}-#{rank}': { width: #{width}, height: #{height} },") end end |
#update(viewports:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/sidekiq/cypress_viewport_updater/viewport_preset_js_file.rb', line 10 def update(viewports:) new_lines = [] raw_content.split("\n").each do |line| if /va-top-(mobile|tablet|desktop)-\d+/.match(line) if /va-top-(mobile|tablet|desktop)-1/.match(line) (line:, viewports:) do |updated_line| new_lines << updated_line end end else new_lines << line end end self.updated_content = "#{new_lines.join("\n")}\n" self end |