Sha256: c11b0d475ee03c32b7b8d4849f45b70d50b49440a68064d873ac7020364b56dc

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

module Dyna
  class DSL
    include Dyna::TemplateHelper

    class << self
      def define(source, path)
        self.new(path) do
          eval(source, binding, path)
        end
      end

      def convert(region, exported)
        Converter.convert(region, exported)
      end
    end

    attr_reader :result

    def initialize(path, &block)
      @path = path
      @result = OpenStruct.new(:ddbs => {})

      @context = Hashie::Mash.new(
        :path      => path,
        :templates => {},
      )

      instance_eval(&block)
    end

    private
    def template(name, &block)
      @context.templates[name.to_s] = block
    end

    def require(file)
      tablefile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))

      if File.exist?(tablefile)
        instance_eval(File.read(tablefile), tablefile)
      elsif File.exist?(tablefile + '.rb')
        instance_eval(File.read(tablefile + '.rb'), tablefile + '.rb')
      else
        Kernel.require(file)
      end
    end

    def dynamo_db(region, &block)
      ddb = @result.ddbs[region]
      tables = ddb ? ddb.tables : []
      @result.ddbs[region] = DynamoDB.new(@context, tables, &block).result
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dyna-0.2.3 lib/dyna/dsl.rb
dyna-0.2.2 lib/dyna/dsl.rb
dyna-0.2.1 lib/dyna/dsl.rb
dyna-0.2.1.beta2 lib/dyna/dsl.rb
dyna-0.2.1.beta1 lib/dyna/dsl.rb
dyna-0.2.0 lib/dyna/dsl.rb
dyna-0.1.9 lib/dyna/dsl.rb
dyna-0.1.8 lib/dyna/dsl.rb
dyna-0.1.7 lib/dyna/dsl.rb
dyna-0.1.6 lib/dyna/dsl.rb
dyna-0.1.5 lib/dyna/dsl.rb
dyna-0.1.4 lib/dyna/dsl.rb
dyna-0.1.3 lib/dyna/dsl.rb
dyna-0.1.2 lib/dyna/dsl.rb
dyna-0.1.1 lib/dyna/dsl.rb