Class: AppBuilder::Environment
- Inherits:
-
Object
- Object
- AppBuilder::Environment
- Defined in:
- lib/app_builder/environment.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #create_file(template_path, output_path) ⇒ Object
-
#initialize(name, source_path) ⇒ Environment
constructor
A new instance of Environment.
- #source ⇒ Object
- #template_binding ⇒ Object
- #to_hash ⇒ Object (also: #hash)
Constructor Details
#initialize(name, source_path) ⇒ Environment
Returns a new instance of Environment.
6 7 8 9 |
# File 'lib/app_builder/environment.rb', line 6 def initialize(name, source_path) @name = name @source_path = source_path end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/app_builder/environment.rb', line 3 def name @name end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
4 5 6 |
# File 'lib/app_builder/environment.rb', line 4 def source_path @source_path end |
Instance Method Details
#[](key) ⇒ Object
24 25 26 |
# File 'lib/app_builder/environment.rb', line 24 def [](key) hash.fetch(key.to_s, nil) end |
#create_file(template_path, output_path) ⇒ Object
11 12 13 14 15 |
# File 'lib/app_builder/environment.rb', line 11 def create_file(template_path, output_path) File.open(output_path, "w") do |f| f.write(ERB.new(File.read(template_path)).result(template_binding)) end end |
#source ⇒ Object
33 34 35 |
# File 'lib/app_builder/environment.rb', line 33 def source @source ||= YAML.load(ERB.new(File.read(source_path)).result(binding)) end |
#template_binding ⇒ Object
17 18 19 20 21 22 |
# File 'lib/app_builder/environment.rb', line 17 def template_binding env = source.fetch(name.to_s) Class.new.tap { |klass| klass.define_method(:env) { env } }.instance_eval { binding } end |
#to_hash ⇒ Object Also known as: hash
28 29 30 |
# File 'lib/app_builder/environment.rb', line 28 def to_hash source.fetch(name.to_s) end |