Class: AppStack::CompareFile
- Inherits:
-
Object
- Object
- AppStack::CompareFile
- Defined in:
- lib/app_stack/compare_list.rb
Overview
items as copy list candidate
Instance Attribute Summary collapse
-
#diff ⇒ Object
Returns the value of attribute diff.
-
#from_app ⇒ Object
Returns the value of attribute from_app.
-
#from_file ⇒ Object
Returns the value of attribute from_file.
-
#import ⇒ Object
Returns the value of attribute import.
-
#render ⇒ Object
Returns the value of attribute render.
-
#to_app ⇒ Object
Returns the value of attribute to_app.
-
#to_file ⇒ Object
Returns the value of attribute to_file.
Instance Method Summary collapse
- #diff? ⇒ Boolean
- #from_file_short_name ⇒ Object
- #import? ⇒ Boolean
-
#initialize(opts) ⇒ CompareFile
constructor
A new instance of CompareFile.
- #label ⇒ Object
- #local_new? ⇒ Boolean
- #operation ⇒ Object
- #process ⇒ Object
- #remote_new? ⇒ Boolean
- #render? ⇒ Boolean
- #skip(msg) ⇒ Object
- #sync? ⇒ Boolean
- #to_file_short_name ⇒ Object
Constructor Details
#initialize(opts) ⇒ CompareFile
9 10 11 12 |
# File 'lib/app_stack/compare_list.rb', line 9 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
#diff ⇒ Object
Returns the value of attribute diff.
7 8 9 |
# File 'lib/app_stack/compare_list.rb', line 7 def diff @diff end |
#from_app ⇒ Object
Returns the value of attribute from_app.
7 8 9 |
# File 'lib/app_stack/compare_list.rb', line 7 def from_app @from_app end |
#from_file ⇒ Object
Returns the value of attribute from_file.
7 8 9 |
# File 'lib/app_stack/compare_list.rb', line 7 def from_file @from_file end |
#import ⇒ Object
Returns the value of attribute import.
7 8 9 |
# File 'lib/app_stack/compare_list.rb', line 7 def import @import end |
#render ⇒ Object
Returns the value of attribute render.
7 8 9 |
# File 'lib/app_stack/compare_list.rb', line 7 def render @render end |
#to_app ⇒ Object
Returns the value of attribute to_app.
7 8 9 |
# File 'lib/app_stack/compare_list.rb', line 7 def to_app @to_app end |
#to_file ⇒ Object
Returns the value of attribute to_file.
7 8 9 |
# File 'lib/app_stack/compare_list.rb', line 7 def to_file @to_file end |
Instance Method Details
#diff? ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/app_stack/compare_list.rb', line 31 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_name ⇒ Object
52 53 54 |
# File 'lib/app_stack/compare_list.rb', line 52 def from_file_short_name from_file.sub(/^#{from_app.directory}\//, '') end |
#import? ⇒ Boolean
18 19 20 |
# File 'lib/app_stack/compare_list.rb', line 18 def import? import ? true : false end |
#label ⇒ Object
60 61 62 63 |
# File 'lib/app_stack/compare_list.rb', line 60 def label "#{operation} #{from_file_short_name.blue} from " + "#{from_app.app_name.bold} as #{to_file_short_name.blue}" end |
#local_new? ⇒ Boolean
43 44 45 |
# File 'lib/app_stack/compare_list.rb', line 43 def local_new? File.exists?(to_file) && File.mtime(to_file) > File.mtime(from_file) end |
#operation ⇒ Object
26 27 28 29 |
# File 'lib/app_stack/compare_list.rb', line 26 def operation return 'render' if render? import? ? 'import' : 'sync' end |
#process ⇒ Object
70 71 72 |
# File 'lib/app_stack/compare_list.rb', line 70 def process render? ? render! : copy! end |
#remote_new? ⇒ Boolean
47 48 49 50 |
# File 'lib/app_stack/compare_list.rb', line 47 def remote_new? return true unless File.exists?(to_file) File.mtime(from_file) > File.mtime(to_file) end |
#render? ⇒ Boolean
14 15 16 |
# File 'lib/app_stack/compare_list.rb', line 14 def render? render ? true : false end |
#skip(msg) ⇒ Object
65 66 67 68 |
# File 'lib/app_stack/compare_list.rb', line 65 def skip(msg) "Skip #{operation} ".white + from_file_short_name.blue + ' from '.white + from_app.app_name.bold + ': ' + msg end |
#sync? ⇒ Boolean
22 23 24 |
# File 'lib/app_stack/compare_list.rb', line 22 def sync? import ? false : true end |
#to_file_short_name ⇒ Object
56 57 58 |
# File 'lib/app_stack/compare_list.rb', line 56 def to_file_short_name to_file.sub(/^#{to_app.directory}\//, '') end |