module Temill::TemillImpl
Implementation of Temill: this module will be both included and extended to Temill
Public Instance Methods
# File lib/temill/core.rb, line 35 def _initialize(**options) @options = DefaultOptions.merge(options) reset end
output results to stdout or any IO @param [IO] f IO to output to
# File lib/temill/core.rb, line 106 def emit(f=$stdout) execute_emitter(Emitters::StdoutEmitter.new(f, @options)) end
output results to files in a directory. a file of original source code corresponds to a output file. @param [String] dir
# File lib/temill/core.rb, line 113 def emit_to_directory(dir) execute_emitter(Emitters::DirectoryEmitter.new(dir, @options)) end
output results to strings. @return [Hash<String,String>] the keys are filenames and the values are the result for the file
# File lib/temill/core.rb, line 119 def emit_to_string execute_emitter(Emitters::StringEmitter.new(@options)) end
same as Kernel.eval, but the evaluated code is handled as if it was an independent file. @param [String] src @param [Binding] bind @param [String] fname
# File lib/temill/core.rb, line 94 def eval(src, bind=TOPLEVEL_BINDING, fname=default_eval_fname(caller_locations.first)) path = EVAL_PATH_PREFIX + Digest::SHA256.hexdigest(src) + '/' + fname @source_files[path] ||= SourceFile.from_inline_source(src, path, @options) Kernel.eval(src, bind, path) end
@param [#call] emitter
# File lib/temill/core.rb, line 124 def execute_emitter(emitter=nil, &block) if emitter emitter.call(@source_files.values, &block) elsif block block.call(@source_files.values) else raise ArgumentError, 'no emitter specified' end end
clear all results added by show
# File lib/temill/core.rb, line 41 def reset # absolute_path => SourceFile @source_files = {} self end
set options @see Temil#initialize
# File lib/temill/core.rb, line 49 def set_options(**options) @options.update(options) self end
store values to be shown. You have to use emit to actually output the results. @overload show(val)
@param [Object] val value to show
@overload show(*vals)
@param [Array<Object>] vals values to show
@overload show(&block)
show the result of block
@return [Object] the object shown
# File lib/temill/core.rb, line 62 def show(*vals, &block) if not vals.empty? and block raise ArgumentError, 'either value or block can be specified' end loc = caller_locations.first path = loc.absolute_path sf = (@source_files[path] ||= SourceFile.from_path(path, @options)) if block obj = block.call else case vals.size when 0 obj = nil when 1 obj = vals.first else obj = vals end end sf.add_result(loc, obj, block_given?) obj end
Private Instance Methods
# File lib/temill/core.rb, line 100 def default_eval_fname(loc) "#{File.basename(loc.path)}:#{loc.lineno}:#{loc.base_label}" end