Class: RUIC
- Inherits:
-
Object
- Object
- RUIC
- Defined in:
- lib/ruic.rb,
lib/ruic.rb,
lib/ruic/version.rb
Overview
The RUIC
class provides the interface for running scripts using the special DSL,
and for running the interactive REPL.
See the README file for description of the DSL.
Constant Summary collapse
- DEFAULTMETADATA =
'C:/Program Files (x86)/NVIDIA Corporation/UI Composer 8.0/res/DataModelMetadata/en-us/MetaData.xml'
- VERSION =
'0.4.6'
Class Method Summary collapse
-
.run(opts = {}) ⇒ nil
Execute a script and/or launch the interactive REPL.
Instance Method Summary collapse
-
#assert(condition = :CONDITIONNOTSUPPLIED, msg = nil, &block) ⇒ Object
Simple assertion mechanism to be used within scripts.
-
#env ⇒ Binding
The shared binding used for evaluating the script and REPL.
-
#initialize(metadata = DEFAULTMETADATA) ⇒ RUIC
constructor
Creates a new environment for executing a RUIC script.
- #inspect ⇒ Object
-
#metadata(path) ⇒ Object
Set the metadata to use; generally called from the RUIC DSL.
-
#method_missing(name, *a) ⇒ UIC::Application
Used to resolve bare
app
andapp2
calls to a loaded Application. -
#show(*a) ⇒ Object
Nicer name for
puts
to be used in the DSL, printing the 'nice' string equivalent for all supplied arguments. -
#uia(path) ⇒ UIC::Application
Load an application, making it available as
app
,app2
, etc.
Constructor Details
#initialize(metadata = DEFAULTMETADATA) ⇒ RUIC
Creates a new environment for executing a RUIC script.
82 83 84 85 |
# File 'lib/ruic.rb', line 82 def initialize( =DEFAULTMETADATA ) @metadata = @apps = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *a) ⇒ UIC::Application
Used to resolve bare app
and app2
calls to a loaded Application.
112 113 114 |
# File 'lib/ruic.rb', line 112 def method_missing(name,*a) @apps[name] || (name=~/^app\d*/ ? "(no #{name} loaded)".extend(SelfInspecting) : super) end |
Class Method Details
.run(opts = {}) ⇒ nil
Execute a script and/or launch the interactive REPL.
If you both run a :script
and then enter the :repl
all local variables created
by the script will be available in the REPL.
# Just run a script
RUIC.run script:'my.ruic'
# Load an application and then enter the REPL
RUIC.run uia:'my.uia', repl:true
# Run a script and then drop into the REPL
RUIC.run script:'my.ruic', repl:true
The working directory for scripts is set to the directory of the script.
The working directory for the repl is set to the directory of the first loaded application (if any); failing that, the directory of the script (if any); failing that, the current directory.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruic.rb', line 47 def self.run(opts={}) opts = opts ruic = nil if opts[:script] script = File.read(opts[:script],encoding:'utf-8') Dir.chdir(File.dirname(opts[:script])) do ruic = self.new ruic.uia(opts[:uia]) if opts[:uia] ruic.env.eval(script,opts[:script]) end end if opts[:repl] location = (ruic && ruic.app && ruic.app.respond_to?(:file) && ruic.app.file) || opts[:uia] || opts[:script] || '.' Dir.chdir( File.dirname(location) ) do ruic ||= self.new.tap{ |r| r.uia(opts[:uia]) if opts[:uia] } require 'ripl/irb' require 'ripl/multi_line' require 'ripl/multi_line/live_error.rb' require_relative 'ruic/ripl-after-result' Ripl::MultiLine.engine = Ripl::MultiLine::LiveError Ripl::Shell.include Ripl::MultiLine.engine Ripl::Shell.include Ripl::AfterResult Ripl.config.merge! prompt:"", result_prompt:'#=> ', multi_line_prompt:' ', irb_verbose:false, after_result:"\n" ARGV.clear # So that RIPL doesn't try to interpret the options puts "(RUIC v#{RUIC::VERSION} interactive session; 'quit' or ctrl-d to end)" ruic.instance_eval{ puts @apps.map{ |n,app| "(#{n} is #{app.inspect})" } } puts "" # blank line before first input Ripl.start binding:ruic.env end end end |
Instance Method Details
#assert(condition = :CONDITIONNOTSUPPLIED, msg = nil, &block) ⇒ Object
Simple assertion mechanism to be used within scripts.
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ruic.rb', line 135 def assert(condition=:CONDITIONNOTSUPPLIED,msg=nil,&block) if block && condition==:CONDITIONNOTSUPPLIED msg = yield condition = msg.is_a?(String) ? eval(msg,block.binding) : msg end condition || begin file, line, _ = caller.first.split(':') puts "#{"#{msg} : " unless msg.nil?}assertion failed (#{file} line #{line})" exit 1 end end |
#env ⇒ Binding
Returns the shared binding used for evaluating the script and REPL.
103 104 105 |
# File 'lib/ruic.rb', line 103 def env @env ||= binding end |
#inspect ⇒ Object
151 152 153 |
# File 'lib/ruic.rb', line 151 def inspect "<RUIC #{@apps.empty? ? "(no app loaded)" : Hash[ @apps.map{ |id,app| [id,File.basename(app.file)] } ]}>" end |
#metadata(path) ⇒ Object
Set the metadata to use; generally called from the RUIC DSL.
89 90 91 |
# File 'lib/ruic.rb', line 89 def (path) @metadata = path end |
#show(*a) ⇒ Object
Nicer name for puts
to be used in the DSL, printing the
'nice' string equivalent for all supplied arguments.
149 |
# File 'lib/ruic.rb', line 149 def show(*a); puts *a.map(&:to_s); end |
#uia(path) ⇒ UIC::Application
Load an application, making it available as app
, app2
, etc.
96 97 98 99 100 |
# File 'lib/ruic.rb', line 96 def uia(path) = UIC.MetaData @metadata name = @apps.empty? ? :app : :"app#{@apps.length+1}" @apps[name] = UIC.Application(,path) end |