Class: PeakFlowUtils::ErbInspector::FileInspector
- Inherits:
-
Object
- Object
- PeakFlowUtils::ErbInspector::FileInspector
- Defined in:
- app/services/peak_flow_utils/erb_inspector/file_inspector.rb
Constant Summary collapse
- JS_FILE_EXTS =
[".coffee", ".coffee.erb", ".es6", ".es6.erb", ".js", ".js.erb"].freeze
- METHOD_NAMES =
%w[t controller_t helper_t].freeze
- VALID_BEGINNING =
'(^|\s+|\(|\{|\[|<%=\s*|I18n\.)'.freeze
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Instance Method Summary collapse
- #basename ⇒ Object
- #changed? ⇒ Boolean
- #full_path ⇒ Object
-
#initialize(args) ⇒ FileInspector
constructor
A new instance of FileInspector.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #translations ⇒ Object
Constructor Details
#initialize(args) ⇒ FileInspector
Returns a new instance of FileInspector.
8 9 10 11 12 13 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 8 def initialize(args) @args = args @root_path = args[:root_path] @file_path = args[:file_path] @method_names ||= ["t"] end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
6 7 8 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 6 def file_path @file_path end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
6 7 8 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 6 def root_path @root_path end |
Instance Method Details
#basename ⇒ Object
42 43 44 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 42 def basename File.basename(@file_path).match(/\A(.+?)\./)[1] end |
#changed? ⇒ Boolean
46 47 48 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 46 def changed? @args.fetch(:changed) end |
#full_path ⇒ Object
38 39 40 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 38 def full_path "#{@root_path}/#{@file_path}" end |
#inspect ⇒ Object
54 55 56 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 54 def inspect to_s end |
#to_s ⇒ Object
50 51 52 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 50 def to_s "<PeakFlowUtils::ErbInspector::FileInspector file_path=\"#{@file_path}\">" end |
#translations ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/peak_flow_utils/erb_inspector/file_inspector.rb', line 15 def translations Enumerator.new do |yielder| File.open(full_path, "r") do |fp| extname = File.extname(full_path) translations_found = [] line_no = 0 fp.each_line do |line| line_no += 1 line = force_utf8(line) if extname == ".liquid" parse_content_liquid(line_no, line, translations_found, yielder) elsif JS_FILE_EXTS.include?(extname) parse_content_js(line_no, line, translations_found, yielder) else parse_content(line_no, line, translations_found, yielder) end end end end end |