Class: Convection::Model::Diff

Inherits:
Object
  • Object
show all
Extended by:
Mixin::Colorize
Defined in:
lib/convection/model/diff.rb

Overview

Difference between an item in two templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Colorize

colorize

Constructor Details

#initialize(key, ours, theirs) ⇒ Diff

Returns a new instance of Diff



17
18
19
20
21
22
23
24
25
26
# File 'lib/convection/model/diff.rb', line 17

def initialize(key, ours, theirs)
  @key = key
  @ours = ours
  @theirs = theirs

  @action = if ours && theirs then :update
            elsif ours then :create
            else :delete
            end
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action



12
13
14
# File 'lib/convection/model/diff.rb', line 12

def action
  @action
end

#keyObject (readonly)

Returns the value of attribute key



11
12
13
# File 'lib/convection/model/diff.rb', line 11

def key
  @key
end

#oursObject (readonly)

Returns the value of attribute ours



13
14
15
# File 'lib/convection/model/diff.rb', line 13

def ours
  @ours
end

#theirsObject (readonly)

Returns the value of attribute theirs



14
15
16
# File 'lib/convection/model/diff.rb', line 14

def theirs
  @theirs
end

Instance Method Details

#to_thorObject



28
29
30
31
32
33
34
35
36
# File 'lib/convection/model/diff.rb', line 28

def to_thor
  message = case action
            when :create then "#{ key }: #{ ours }"
            when :update then "#{ key }: #{ theirs } => #{ ours }"
            when :delete then key
            end

  [action, message, color]
end