Class: Modulofcm::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/modulofcm/configurator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurator

Returns a new instance of Configurator.



9
10
11
# File 'lib/modulofcm/configurator.rb', line 9

def initialize
  @clients = {}
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



7
8
9
# File 'lib/modulofcm/configurator.rb', line 7

def clients
  @clients
end

Class Method Details

.configure {|builder| ... } ⇒ Object

Yields:

  • (builder)

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
# File 'lib/modulofcm/configurator.rb', line 13

def self.configure
  raise ArgumentError, 'A block is needed for Modulofcm.configure' unless block_given?

  builder = new
  yield builder

  Modulofcm.clients = builder.clients
end

Instance Method Details

#client(name) {|client| ... } ⇒ Object

Yields:

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/modulofcm/configurator.rb', line 22

def client(name)
  raise ArgumentError, 'A block is needed for Modulofcm::Configurator.client' unless block_given?

  client = Client.new(name: name)
  yield client

  validated_client, errors = validate_client(client)
  raise InvalidClient, errors.join('; ') unless validated_client

  @clients[name] = client
end