Class: Fare::ConfigurationDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/fare/configuration_dsl.rb

Overview

This class is the context in which the fare config file is loaded. It provides a DSL that fills a configuration object.

Defined Under Namespace

Classes: StackDSL, SubscriberDSL

Constant Summary collapse

InvalidOption =
Class.new(ArgumentError)
VALID_PART_OF_TOPIC_NAME =
/\A\w+\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurationDSL

Returns a new instance of ConfigurationDSL.



12
13
14
# File 'lib/fare/configuration_dsl.rb', line 12

def initialize
  @configuration = Configuration.new
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



10
11
12
# File 'lib/fare/configuration_dsl.rb', line 10

def configuration
  @configuration
end

Instance Method Details

#app_name(name) ⇒ Object



21
22
23
24
# File 'lib/fare/configuration_dsl.rb', line 21

def app_name(name)
  validate! "App name", name
  configuration.app_name = name
end

#app_version(version) ⇒ Object



30
31
32
# File 'lib/fare/configuration_dsl.rb', line 30

def app_version(version)
  configuration.app_version = version
end

#backup!Object



34
35
36
# File 'lib/fare/configuration_dsl.rb', line 34

def backup!
  configuration.backup!
end

#default_version(version) ⇒ Object



26
27
28
# File 'lib/fare/configuration_dsl.rb', line 26

def default_version(version)
  configuration.default_version = version
end

#environment(name, &block) ⇒ Object



16
17
18
19
# File 'lib/fare/configuration_dsl.rb', line 16

def environment(name, &block)
  validate! "Environment", name.to_s
  configuration.environments[name.to_s] = block
end

#publishes(topic) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fare/configuration_dsl.rb', line 38

def publishes(topic)
  topic.each do |key, value|
    case key
    when :subject then validate! "Subject", value
    when :action  then validate! "Action", value
    when :version then true
    else
      raise InvalidOption, "Unknown option: #{key}"
    end
  end
  configuration.publish_topics << topic
end

#subscriber(name = configuration.app_name, &block) ⇒ Object



51
52
53
54
# File 'lib/fare/configuration_dsl.rb', line 51

def subscriber(name = configuration.app_name, &block)
  config = configuration.subscriber(name)
  SubscriberDSL.new(config).parse(&block)
end