Class: BooticCli::Themes::UpdatedTheme

Inherits:
Object
  • Object
show all
Defined in:
lib/bootic_cli/themes/updated_theme.rb

Overview

given :source and :target themes, UpdatedTheme computes assets and templates with more recent versions in :source

Defined Under Namespace

Classes: TemplateWithDiff

Instance Method Summary collapse

Constructor Details

#initialize(source:, target:, force_update: false) ⇒ UpdatedTheme



11
12
13
14
15
16
# File 'lib/bootic_cli/themes/updated_theme.rb', line 11

def initialize(source:, target:, force_update: false)
  @source, @target = source, target
  # when doing a pull or push, we don't care if the other end has a more recent version
  # we only do that when syncing changes, in which case force_update should be false
  @force_update = force_update
end

Instance Method Details

#any?Boolean



18
19
20
# File 'lib/bootic_cli/themes/updated_theme.rb', line 18

def any?
  templates.any? # || assets.any?
end

#assetsObject



34
35
36
37
38
# File 'lib/bootic_cli/themes/updated_theme.rb', line 34

def assets
  @assets ||= map_pair(source.assets, target.assets) do |a, b|
    [should_update?(a, b), a]
  end
end

#templatesObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bootic_cli/themes/updated_theme.rb', line 22

def templates
  @templates ||= map_pair(source.templates, target.templates) do |a, b|
    diff = Diffy::Diff.new(normalize_endings(b.body), normalize_endings(a.body), context: 1)
    if !diff.to_s.empty? && should_update?(a, b)
      c = TemplateWithDiff.new(a.file_name, a.body, a.updated_on, diff)
      [true, c]
    else
      [false, nil]
    end
  end
end