Class: Mutant::Zombifier::File
- Inherits:
-
Object
- Object
- Mutant::Zombifier::File
- Includes:
- Adamantium::Flat
- Defined in:
- lib/mutant/zombifier.rb
Overview
File containing source beeing zombified
Constant Summary collapse
- CACHE =
{}
- RECEIVER_INDEX =
0
- SELECTOR_INDEX =
1
- ARGUMENT_INDEX =
2..-1.freeze
Class Method Summary collapse
-
.find(logical_name) ⇒ File
private
Find file.
-
.find_uncached(logical_name) ⇒ File?
private
Find file without cache.
Instance Method Summary collapse
-
#node ⇒ Parser::AST::Node
private
Return node.
-
#required_paths ⇒ Enumerable<String>
private
Return required paths.
-
#subject ⇒ Subject
private
Return subject.
-
#zombify ⇒ self
private
Zombify contents of file.
Class Method Details
.find(logical_name) ⇒ File
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find file
129 130 131 132 133 134 |
# File 'lib/mutant/zombifier.rb', line 129 def self.find(logical_name) return if IGNORE.include?(logical_name) CACHE.fetch(logical_name) do CACHE[logical_name] = find_uncached(logical_name) end end |
.find_uncached(logical_name) ⇒ File?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find file without cache
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/mutant/zombifier.rb', line 148 def self.find_uncached(logical_name) file_name = if logical_name.end_with?('.rb') logical_name else "#{logical_name}.rb" end $LOAD_PATH.each do |path| path = Pathname.new(path).join(file_name) if path.file? return new(path) end end $stderr.puts "Cannot find file #{file_name} in $LOAD_PATH" nil end |
Instance Method Details
#node ⇒ Parser::AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return node
184 185 186 |
# File 'lib/mutant/zombifier.rb', line 184 def node Parser::CurrentRuby.parse(::File.read(source_path)) end |
#required_paths ⇒ Enumerable<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return required paths
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/mutant/zombifier.rb', line 199 def required_paths require_nodes.map do |node| arguments = node.children[ARGUMENT_INDEX] unless arguments.length == 1 raise "Require node with not exactly one argument: #{node}" end argument = arguments.first unless argument.type == :str raise "Require argument is not a literal string: #{argument}" end argument.children.first end end |
#subject ⇒ Subject
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return subject
173 174 175 |
# File 'lib/mutant/zombifier.rb', line 173 def subject Subject.new(self) end |
#zombify ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Zombify contents of file
106 107 108 109 110 111 112 113 114 |
# File 'lib/mutant/zombifier.rb', line 106 def zombify subject.zombify required_paths.each do |path| file = File.find(path) next unless file file.zombify end self end |