Sha256: 35f5429ab6378ebe62bede7d66215f50284eef2ee8f3aca15557625b160db465

Contents?: true

Size: 637 Bytes

Versions: 2

Compression:

Stored size: 637 Bytes

Contents

module AppBuilder
  class Environment
    attr_accessor :name
    attr_reader :source_path

    def initialize(name, source_path)
      @name        = name
      @source_path = source_path
    end

    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

    def template_binding
      env = source.fetch(name.to_s)
      Class.new.tap { |klass|
        klass.define_method(:env) { env }
      }.instance_eval { binding }
    end

    def source
      @source ||= YAML.load_file(source_path)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
app_builder-0.1.9 lib/app_builder/environment.rb
app_builder-0.1.8 lib/app_builder/environment.rb