Module: RubyBreaker
- Defined in:
- lib/rubybreaker.rb,
lib/rubybreaker/util.rb,
lib/rubybreaker/runtime.rb,
lib/rubybreaker/doc/rdoc.rb,
lib/rubybreaker/type/type.rb,
lib/rubybreaker/debug/debug.rb,
lib/rubybreaker/debug/error.rb,
lib/rubybreaker/runtime/util.rb,
lib/rubybreaker/debug/context.rb,
lib/rubybreaker/runtime/monitor.rb,
lib/rubybreaker/typing/rubytype.rb,
lib/rubybreaker/typing/subtyping.rb,
lib/rubybreaker/runtime/inspector.rb,
lib/rubybreaker/runtime/overrides.rb,
lib/rubybreaker/runtime/pluggable.rb,
lib/rubybreaker/type/type_comparer.rb,
lib/rubybreaker/type/type_unparser.rb,
lib/rubybreaker/runtime/type_system.rb,
lib/rubybreaker/runtime/object_wrapper.rb,
lib/rubybreaker/runtime/typesig_parser.rb,
lib/rubybreaker/runtime/typesig_unparser.rb
Overview
– This file contains a module that explains what is eligible to be a pluggable type system (or anything really). (Think of AOP but for metod calls only.)
Defined Under Namespace
Modules: Breakable, Broken, Errors, RDocSupport, RubyTypeUtils, Runtime, TypeComparer, TypeDefs, TypeUnparser, Typing, Util Classes: Context, ObjectPosition, Position
Constant Summary collapse
- OPTIONS =
Options for RubyBreaker
{ :debug => false, # in debug mode? :style => :underscore, # type signature style-underscore or camelize :io_file => nil, # generate input/output other than default? :append => false, # append to the input file (if there is)? :stdout => false, # also display on the screen? :verbose => false, # in RubyBreaker.verbose mode? :save_output => true, # save output to a file? :break => [], # modules/classes to break :check => [], # modules/classes to check :libs => [], # list of library files to import :prog => nil, # program or test file }
- OPTION_PARSER =
This option parser may be used for the command-line mode or for the library mode when used with Rakefile. See rubybreaker/task.rb for how this can be used in the latter.
OptionParser.new do |opts| opts. = "Usage: #{File.basename(__FILE__)} [options] prog[.rb]" opts.on("-b MODULES", "--break MODULES", "Specify modules/classes to 'break'") do |s| tokens = s.split(/[;,]/) tokens.each {|t| OPTIONS[:break] << t} end opts.on("-c MODULES", "--check MODULES", "Specify modules/classes to check") do |s| tokens = s.split(/[;,]/) tokens.each {|t| OPTIONS[:check] << t} end opts.on("-l LIBRARIES", "--libs LIBRARIES", "Specify libraries to load") do |s| tokens = s.split(":") tokens.each {|t| OPTIONS[:libs] << t} end opts.on("--debug", "Run in debug mode") do OPTIONS[:debug] = true end opts.on("--style STYLE", "Select type signature style - underscore or camelize") do |v| OPTIONS[:style] = v.downcase.to_sym end opts.on("--io-file FILE","Specify I/O file") do |f| OPTIONS[:io_file] = f end opts.on("--save-output", "Save output to file") do b| OPTIONS[:save_output] = b end opts.on("-s","--[no-]stdout","Show output on screen") do |b| OPTIONS[:stdout] = b end opts.on("-a", "--[no-]append", "Append output to input file") do |b| OPTIONS[:append] = b end opts.on("-v","--verbose","Show messages in detail") do OPTIONS[:verbose] = true end opts.on("-h","--help","Show this help text") do puts opts exit end end
- COPYRIGHT =
This constant contains the copyright information.
"Copyright (c) 2012 Jong-hoon (David) An. All Rights Reserved."
- TASK_EXTENSION =
Extension used for files that contain RubyBreaker task information
"rb"
- YAML_EXTENSION =
Extension used for files that contain type information in YAML format
"yaml"
- IO_EXTENSION =
Extension used for files that contain type information in Ruby format
"rubybreaker.rb"
Constants included from Runtime
Runtime::BLACKLIST, Runtime::BREAKABLES, Runtime::CONTEXT, Runtime::DEFAULT_TYPE_SYSTEM, Runtime::GLOBAL_MONITOR_SWITCH, Runtime::MONITOR_MAP, Runtime::OVERRIDE_PREFIX, Runtime::TYPE_MAP, Runtime::WHITELIST, Runtime::WRAPPED_INDICATOR
Class Method Summary collapse
-
.break(*mods) ⇒ Object
This method just redirects to Runtime’s method.
-
.breakable(*mods) ⇒ Object
This method just redirects to Runtime’s method.
- .check(*mods) ⇒ Object
-
.defined_logger? ⇒ Boolean
This method returns true if the logger is already created and false otherwise.
-
.error(err, level = :error, &blk) ⇒ Object
This method is for reporting an error to the user.
-
.log(str, level = :debug, context = nil, &blk) ⇒ Object
This method logs a non-error (or error) message but with the provided context.
-
.monitor ⇒ Object
DEPRECATED: Use RubyBreaker.run() to indicate the point of entry.
-
.run(*mods) ⇒ Object
This method runs RubyBreaker for a particular test case (class).
-
.setup_logger ⇒ Object
This sets up the logger for debugging RubyBreaker.
-
.verbose(str, &blk) ⇒ Object
This method will display verbose message.
Methods included from Runtime
Class Method Details
.break(*mods) ⇒ Object
This method just redirects to Runtime’s method.
93 94 95 |
# File 'lib/rubybreaker/runtime.rb', line 93 def self.break(*mods) Runtime.break(*mods) end |
.breakable(*mods) ⇒ Object
This method just redirects to Runtime’s method. DEPRECATED: Use RubyBreaker.break() to indicate the point of entry.
88 89 90 |
# File 'lib/rubybreaker/runtime.rb', line 88 def self.breakable(*mods) Runtime.breakable(*mods) end |
.check(*mods) ⇒ Object
97 98 99 |
# File 'lib/rubybreaker/runtime.rb', line 97 def self.check(*mods) Runtime.check(*mods) end |
.defined_logger? ⇒ Boolean
This method returns true if the logger is already created and false otherwise.
13 14 15 |
# File 'lib/rubybreaker/debug/debug.rb', line 13 def self.defined_logger?() return defined?(LOGGER) end |
.error(err, level = :error, &blk) ⇒ Object
This method is for reporting an error to the user. It will immediately show the error message but also log it.
44 45 46 47 48 49 |
# File 'lib/rubybreaker/debug/debug.rb', line 44 def self.error(err, level=:error, &blk) msg = err.to_s msg = "#{msg} : #{yield}" if blk STDOUT.puts "[#{level.to_s.upcase}] #{msg}" LOGGER.send(level, msg) if defined?(OPTIONS) && OPTIONS[:debug] end |
.log(str, level = :debug, context = nil, &blk) ⇒ Object
This method logs a non-error (or error) message but with the provided context.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubybreaker/debug/debug.rb', line 53 def self.log(str, level=:debug, context=nil, &blk) return unless defined?(OPTIONS) && OPTIONS[:debug] msg = str.to_s msg = "#{msg} : #{yield}" if blk if context output = "" pp = PrettyPrint.new(output) context.format_with_msg(pp,msg) pp.flush msg = output end LOGGER.send(level, msg) end |
.monitor ⇒ Object
DEPRECATED: Use RubyBreaker.run() to indicate the point of entry.
83 84 |
# File 'lib/rubybreaker/runtime.rb', line 83 def self.monitor() end |
.run(*mods) ⇒ Object
This method runs RubyBreaker for a particular test case (class). This is a bit different from running RubyBreaker as a shell program.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/rubybreaker.rb', line 175 def self.run(*mods) RubyBreaker.setup_logger() unless RubyBreaker.defined_logger?() # Task based run should use the rubybreaker options same as in shell # mode. So, parse the options first. if self.running_as_task?() # running in task mode RubyBreaker.verbose("Running RubyBreaker within a testcase") task = self.task OPTION_PARSER.parse(*task[:rubybreaker_opts]) Runtime.break(*task[:break]) Runtime.check(*task[:check]) task_name = task[:name] RubyBreaker.verbose("Done reading task information") io_file = self.io_file(task_name) elsif OPTIONS[:prog] # running in shell mode Runtime.break(*mods) # should not happen but for backward-compatibility Runtime.break(*OPTIONS[:break]) Runtime.check(*OPTIONS[:check]) io_file = self.io_file(OPTIONS[:prog_file]) else # Otherwise, assume there are no explicit IO files. end self.load_input(io_file) # The following is deprecated but doing this for backward compatibility Runtime.instrument() # At the end, we WILL generate an output of the type information. at_exit { self.output(io_file) } end |
.setup_logger ⇒ Object
This sets up the logger for debugging RubyBreaker
18 19 20 21 22 23 24 25 26 |
# File 'lib/rubybreaker/debug/debug.rb', line 18 def self.setup_logger #:nodoc: return if defined?(LOGGER) out = if (defined?(OPTIONS) && OPTIONS[:debug] && !OPTIONS[:file].empty?) then "#{OPTIONS[:file]}.log" else STDOUT end const_set(:LOGGER, Logger.new(out)) LOGGER.level = Logger::DEBUG end |
.verbose(str, &blk) ⇒ Object
This method will display verbose message. It is not for debugging but to inform users of each stage in the analysis.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubybreaker/debug/debug.rb', line 30 def self.verbose(str, &blk) return unless defined?(OPTIONS) && (OPTIONS[:verbose] || OPTIONS[:debug]) if blk msg = yield msg = "#{str} : #{msg}" if str else msg = str end STDOUT.puts msg if OPTIONS[:verbose] LOGGER.info msg if OPTIONS[:debug] end |