Class: SashimiTanpopo::DSL::EvalContext
- Inherits:
-
Object
- Object
- SashimiTanpopo::DSL::EvalContext
- Defined in:
- lib/sashimi_tanpopo/dsl.rb
Instance Method Summary collapse
-
#changed_files ⇒ Hash<String, { before_content: String, after_content: String, mode: String }>
Key: file path, value: Hash.
-
#dry_run? ⇒ Boolean
Whether dry run.
-
#initialize(params:, dry_run:, is_colored:, target_dir:, is_update_local:) ⇒ EvalContext
constructor
A new instance of EvalContext.
-
#params ⇒ Hash<Symbol, String>
passed from
--params
. -
#update_file(pattern) {|content| ... } ⇒ Object
Update files if exists.
Constructor Details
#initialize(params:, dry_run:, is_colored:, target_dir:, is_update_local:) ⇒ EvalContext
Returns a new instance of EvalContext.
68 69 70 71 72 73 74 75 |
# File 'lib/sashimi_tanpopo/dsl.rb', line 68 def initialize(params:, dry_run:, is_colored:, target_dir:, is_update_local:) @__params__ = params @__dry_run__ = dry_run @__target_dir__ = target_dir @__is_update_local__ = is_update_local @__diffy_format__ = is_colored ? :color : :text end |
Instance Method Details
#changed_files ⇒ Hash<String, { before_content: String, after_content: String, mode: String }>
Returns key: file path, value: Hash.
94 95 96 |
# File 'lib/sashimi_tanpopo/dsl.rb', line 94 def changed_files @__changed_files__ ||= {} end |
#dry_run? ⇒ Boolean
Returns Whether dry run.
104 105 106 |
# File 'lib/sashimi_tanpopo/dsl.rb', line 104 def dry_run? @__dry_run__ end |
#params ⇒ Hash<Symbol, String>
passed from --params
89 90 91 |
# File 'lib/sashimi_tanpopo/dsl.rb', line 89 def params @__params__ end |
#update_file(pattern) {|content| ... } ⇒ Object
Update files if exists
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/sashimi_tanpopo/dsl.rb', line 123 def update_file(pattern, &block) Dir.glob(pattern).each do |path| full_file_path = File.join(@__target_dir__, path) before_content = File.read(full_file_path) SashimiTanpopo.logger.info "Checking #{full_file_path}" after_content = update_single_file(path, &block) unless after_content SashimiTanpopo.logger.info "#{full_file_path} isn't changed" next end changed_files[path] = { before_content: before_content, after_content: after_content, mode: File.stat(full_file_path).mode.to_s(8) } if dry_run? SashimiTanpopo.logger.info "#{full_file_path} will be changed (dryrun)" else SashimiTanpopo.logger.info "#{full_file_path} is changed" end end end |