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

Returns a new instance of UpdatedTheme.



20
21
22
23
24
25
# File 'lib/bootic_cli/themes/updated_theme.rb', line 20

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/bootic_cli/themes/updated_theme.rb', line 27

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

#assetsObject



48
49
50
51
52
# File 'lib/bootic_cli/themes/updated_theme.rb', line 48

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

#countObject



31
32
33
# File 'lib/bootic_cli/themes/updated_theme.rb', line 31

def count
  templates.count
end

#templatesObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bootic_cli/themes/updated_theme.rb', line 35

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