Class: HeyDan::ScriptFile
- Inherits:
-
Object
- Object
- HeyDan::ScriptFile
- Defined in:
- lib/heydan/script_file.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#name ⇒ Object
Returns the value of attribute name.
-
#script_file_path ⇒ Object
Returns the value of attribute script_file_path.
-
#script_folder_path ⇒ Object
Returns the value of attribute script_folder_path.
-
#source ⇒ Object
Returns the value of attribute source.
-
#variable ⇒ Object
Returns the value of attribute variable.
Instance Method Summary collapse
- #create_class_name ⇒ Object
- #create_script_folder ⇒ Object
- #eval_class ⇒ Object
-
#initialize(folder, source, variable) ⇒ ScriptFile
constructor
A new instance of ScriptFile.
- #save ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(folder, source, variable) ⇒ ScriptFile
Returns a new instance of ScriptFile.
11 12 13 14 15 16 17 |
# File 'lib/heydan/script_file.rb', line 11 def initialize(folder, source, variable) @folder, @source, @variable = folder, source, variable @name = @folder + "_" + @source + "_" + @variable create_class_name @script_folder_path = File.join(HeyDan.folders[:sources], @folder, 'scripts') @script_file_path = File.join(@script_folder_path, "#{@name}.rb") end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
7 8 9 |
# File 'lib/heydan/script_file.rb', line 7 def class_name @class_name end |
#folder ⇒ Object
Returns the value of attribute folder.
2 3 4 |
# File 'lib/heydan/script_file.rb', line 2 def folder @folder end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/heydan/script_file.rb', line 8 def name @name end |
#script_file_path ⇒ Object
Returns the value of attribute script_file_path.
6 7 8 |
# File 'lib/heydan/script_file.rb', line 6 def script_file_path @script_file_path end |
#script_folder_path ⇒ Object
Returns the value of attribute script_folder_path.
5 6 7 |
# File 'lib/heydan/script_file.rb', line 5 def script_folder_path @script_folder_path end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/heydan/script_file.rb', line 3 def source @source end |
#variable ⇒ Object
Returns the value of attribute variable.
4 5 6 |
# File 'lib/heydan/script_file.rb', line 4 def variable @variable end |
Instance Method Details
#create_class_name ⇒ Object
23 24 25 |
# File 'lib/heydan/script_file.rb', line 23 def create_class_name @class_name = @name.split('_').collect(&:capitalize).join end |
#create_script_folder ⇒ Object
19 20 21 |
# File 'lib/heydan/script_file.rb', line 19 def create_script_folder FileUtils.mkdir_p @script_folder_path if !Dir.exist?(@script_folder_path) end |
#eval_class ⇒ Object
41 42 43 44 |
# File 'lib/heydan/script_file.rb', line 41 def eval_class load script_file_path return eval("#{@class_name}") end |
#save ⇒ Object
34 35 36 37 38 39 |
# File 'lib/heydan/script_file.rb', line 34 def save create_script_folder File.open(@script_file_path, 'w') do |f| f.write(template) end end |
#template ⇒ Object
27 28 29 30 31 32 |
# File 'lib/heydan/script_file.rb', line 27 def template template_path = File.join(File.dirname(__FILE__), 'templates', 'script.rb.erb') require 'erb' ERB.new(File.read(template_path)).result binding end |