Class: Victor::CLI::RubySource
- Inherits:
-
Object
- Object
- Victor::CLI::RubySource
- Includes:
- DSL
- Defined in:
- lib/victor/cli/ruby_source.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#global_params ⇒ Object
readonly
Returns the value of attribute global_params.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #evaluate(local_params = nil) ⇒ Object
-
#initialize(code, filename: nil, params: nil) ⇒ RubySource
constructor
A new instance of RubySource.
- #template(template) ⇒ Object
Constructor Details
#initialize(code, filename: nil, params: nil) ⇒ RubySource
Returns a new instance of RubySource.
8 9 10 11 12 13 |
# File 'lib/victor/cli/ruby_source.rb', line 8 def initialize(code, filename: nil, params: nil) @code = code @filename = filename @global_params = params || {} @params = global_params end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/victor/cli/ruby_source.rb', line 6 def code @code end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/victor/cli/ruby_source.rb', line 6 def filename @filename end |
#global_params ⇒ Object (readonly)
Returns the value of attribute global_params.
6 7 8 |
# File 'lib/victor/cli/ruby_source.rb', line 6 def global_params @global_params end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/victor/cli/ruby_source.rb', line 6 def params @params end |
Instance Method Details
#evaluate(local_params = nil) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/victor/cli/ruby_source.rb', line 15 def evaluate(local_params = nil) @params = local_params || global_params if filename instance_eval code, filename else instance_eval code end end |
#template(template) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/victor/cli/ruby_source.rb', line 24 def template(template) if built_in_templates.include? template template = template.to_sym elsif !File.exist? template raise "Template not found #{template}\nAvailable templates: #{built_in_templates.join ', '}, or a file path" end svg.template = template end |