Class: Simnos::DSL

Inherits:
Object
  • Object
show all
Includes:
TemplateHelper
Defined in:
lib/simnos/dsl.rb,
lib/simnos/dsl/sns.rb,
lib/simnos/dsl/topic.rb,
lib/simnos/dsl/subscription.rb,
lib/simnos/dsl/subscriptions.rb

Defined Under Namespace

Classes: SNS, Subscription, Subscriptions, Topic

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TemplateHelper

#context, #include_template

Constructor Details

#initialize(filepath, options, &block) ⇒ DSL

Returns a new instance of DSL.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simnos/dsl.rb', line 19

def initialize(filepath, options, &block)
  @filepath = filepath
  @result = OpenStruct.new(snss: Hashie::Mash.new)

  @context = Hashie::Mash.new(
    filepath: filepath,
    templates: {},
    options: options,
  )

  instance_eval(&block)
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



17
18
19
# File 'lib/simnos/dsl.rb', line 17

def result
  @result
end

Class Method Details

.define(source, filepath, options) ⇒ Object



10
11
12
13
14
# File 'lib/simnos/dsl.rb', line 10

def define(source, filepath, options)
  self.new(filepath, options) do
    eval(source, binding, filepath)
  end
end

Instance Method Details

#require(file) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/simnos/dsl.rb', line 32

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

  if File.exist?(albfile)
    instance_eval(File.read(albfile), albfile)
  elsif File.exist?("#{albfile}.rb")
    instance_eval(File.read("#{albfile}.rb"), "#{albfile}.rb")
  else
    Kernel.require(file)
  end
end

#sns(region = nil, &block) ⇒ Object



48
49
50
51
52
53
# File 'lib/simnos/dsl.rb', line 48

def sns(region = nil, &block)
  current_region = @context[:region] = region || ENV['AWS_DEFAULT_REGION'] || ENV.fetch('AWS_REGION')
  current_region_sns = @result.snss[current_region]
  topics = current_region_sns ? current_region_sns.topics : []
  @result.snss[current_region] = SNS.new(@context, topics, &block).result
end

#template(name, &block) ⇒ Object



44
45
46
# File 'lib/simnos/dsl.rb', line 44

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