Class: Victor::CLI::RubySource

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/victor/cli/ruby_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/victor/cli/ruby_source.rb', line 6

def code
  @code
end

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/victor/cli/ruby_source.rb', line 6

def filename
  @filename
end

#global_paramsObject (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

#paramsObject (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