Class: AppStack::CompareFile

Inherits:
Object
  • Object
show all
Defined in:
lib/app_stack/compare_list.rb

Overview

items as copy list candidate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ CompareFile

Returns a new instance of CompareFile.



8
9
10
11
# File 'lib/app_stack/compare_list.rb', line 8

def initialize(opts)
  opts.each { |k, v| send("#{k}=".to_sym, v) }
  @to_file ||= to_app.get_file_path(from_file_short_name)
end

Instance Attribute Details

#diffObject

Returns the value of attribute diff.



6
7
8
# File 'lib/app_stack/compare_list.rb', line 6

def diff
  @diff
end

#from_appObject

Returns the value of attribute from_app.



6
7
8
# File 'lib/app_stack/compare_list.rb', line 6

def from_app
  @from_app
end

#from_fileObject

Returns the value of attribute from_file.



6
7
8
# File 'lib/app_stack/compare_list.rb', line 6

def from_file
  @from_file
end

#importObject

Returns the value of attribute import.



6
7
8
# File 'lib/app_stack/compare_list.rb', line 6

def import
  @import
end

#renderObject

Returns the value of attribute render.



6
7
8
# File 'lib/app_stack/compare_list.rb', line 6

def render
  @render
end

#to_appObject

Returns the value of attribute to_app.



6
7
8
# File 'lib/app_stack/compare_list.rb', line 6

def to_app
  @to_app
end

#to_fileObject

Returns the value of attribute to_file.



6
7
8
# File 'lib/app_stack/compare_list.rb', line 6

def to_file
  @to_file
end

Instance Method Details

#diff?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/app_stack/compare_list.rb', line 37

def diff?
  return true unless File.exists?(to_file)
  c_file = from_file
  if render?
    c_file = Tempfile.new(File.basename(from_file)).path
    render! c_file
  end

  @diff ||= Diffy::Diff.new(to_file, c_file, source: 'files')
  @diff && @diff.to_s.chomp.size > 0 ? true : false
end

#from_file_short_nameObject



58
59
60
# File 'lib/app_stack/compare_list.rb', line 58

def from_file_short_name
  from_file.sub(/^#{from_app.directory}\//, '')
end

#import?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/app_stack/compare_list.rb', line 24

def import?
  import ? true : false
end

#labelObject



66
67
68
69
70
71
72
# File 'lib/app_stack/compare_list.rb', line 66

def label
  str = "#{operation} #{from_file_short_name.blue} from " +
        "#{from_app.app_name.bold}"
  str << "as #{to_file_short_name.blue}" unless
    to_file_short_name == from_file_short_name
  str
end

#local_new?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/app_stack/compare_list.rb', line 49

def local_new?
  File.exists?(to_file) && File.mtime(to_file) > File.mtime(from_file)
end

#operationObject



32
33
34
35
# File 'lib/app_stack/compare_list.rb', line 32

def operation
  return 'render' if render?
  import? ? 'import' : 'sync'
end

#processObject



83
84
85
86
# File 'lib/app_stack/compare_list.rb', line 83

def process
  puts label
  render? ? render! : copy!
end

#remote_new?Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/app_stack/compare_list.rb', line 53

def remote_new?
  return true unless File.exists?(to_file)
  File.mtime(from_file) > File.mtime(to_file)
end

#render?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/app_stack/compare_list.rb', line 20

def render?
  render ? true : false
end

#reverse!Object



13
14
15
16
17
18
# File 'lib/app_stack/compare_list.rb', line 13

def reverse!
  fail 'can not reverse an import or render item' if import? || render?
  from_app_, from_file_ = from_app.dup, from_file.dup
  @from_app, @from_file = to_app, to_file
  @to_app, @to_file = from_app_, from_file_
end

#reverse_labelObject



74
75
76
# File 'lib/app_stack/compare_list.rb', line 74

def reverse_label
  "Copy back #{from_file_short_name.blue} to #{to_app.app_name.bold}"
end

#skip(msg) ⇒ Object



78
79
80
81
# File 'lib/app_stack/compare_list.rb', line 78

def skip(msg)
  "Skip #{operation} ".white + from_file_short_name.blue + ' from '.white +
  from_app.app_name.bold + ': ' + msg
end

#sync?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/app_stack/compare_list.rb', line 28

def sync?
  import ? false : true
end

#to_file_short_nameObject



62
63
64
# File 'lib/app_stack/compare_list.rb', line 62

def to_file_short_name
  to_file.sub(/^#{to_app.directory}\//, '')
end