Class: Dehenzify::ExtractedSource
- Inherits:
-
Struct
- Object
- Struct
- Dehenzify::ExtractedSource
- Defined in:
- lib/dehenzify/extracted_source.rb
Instance Attribute Summary collapse
-
#namespace_modules ⇒ Object
Returns the value of attribute namespace_modules.
-
#node ⇒ Object
Returns the value of attribute node.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target_file_path ⇒ Object
Returns the value of attribute target_file_path.
Instance Method Summary collapse
Instance Attribute Details
#namespace_modules ⇒ Object
Returns the value of attribute namespace_modules
2 3 4 |
# File 'lib/dehenzify/extracted_source.rb', line 2 def namespace_modules @namespace_modules end |
#node ⇒ Object
Returns the value of attribute node.
4 5 6 |
# File 'lib/dehenzify/extracted_source.rb', line 4 def node @node end |
#source ⇒ Object
Returns the value of attribute source
2 3 4 |
# File 'lib/dehenzify/extracted_source.rb', line 2 def source @source end |
#target_file_path ⇒ Object
Returns the value of attribute target_file_path
2 3 4 |
# File 'lib/dehenzify/extracted_source.rb', line 2 def target_file_path @target_file_path end |
Instance Method Details
#delete! ⇒ Object
38 39 40 |
# File 'lib/dehenzify/extracted_source.rb', line 38 def delete! File.delete(target_file_path) if exists? end |
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/dehenzify/extracted_source.rb', line 24 def empty? source.blank? || Dehenzify::Extractor.empty_node?(Parser::CurrentRuby.parse(source)) end |
#exists? ⇒ Boolean
28 29 30 |
# File 'lib/dehenzify/extracted_source.rb', line 28 def exists? File.exists?(target_file_path) end |
#namespaced_source ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dehenzify/extracted_source.rb', line 6 def namespaced_source raw_namespaced_source = source namespace_modules.reverse_each.with_index(1) do |module_name, index| space_offset = ' ' * (namespace_modules.size - index) modulized_source = '' modulized_source << "module #{module_name}" << "\n" modulized_source << space_offset << ' ' modulized_source << raw_namespaced_source << "\n" modulized_source << space_offset << 'end' raw_namespaced_source = modulized_source end if namespace_modules raw_namespaced_source << "\n" unless raw_namespaced_source.end_with?("\n") raw_namespaced_source end |
#write! ⇒ Object
32 33 34 35 36 |
# File 'lib/dehenzify/extracted_source.rb', line 32 def write! FileUtils.mkdir_p(File.dirname(target_file_path)) File.write(target_file_path, namespaced_source) target_file_path end |