Class: Openbill::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/openbill/registry.rb

Constant Summary collapse

DEFAULT_CATEGORY =
:common
AccountNotFound =
Class.new StandardError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, category = DEFAULT_CATEGORY) {|_self| ... } ⇒ Registry

Returns a new instance of Registry.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
14
15
# File 'lib/openbill/registry.rb', line 8

def initialize(service, category = DEFAULT_CATEGORY)
  fail("Must be a Openbill::Service #{service}") unless service.is_a? Openbill::Service
  @service = service
  @category = category
  @accounts = {}
  yield self
  @accounts.freeze
end

Instance Attribute Details

#accountsObject (readonly)

Returns the value of attribute accounts.



6
7
8
# File 'lib/openbill/registry.rb', line 6

def accounts
  @accounts
end

Instance Method Details

#[](name) ⇒ Object



23
24
25
# File 'lib/openbill/registry.rb', line 23

def [](name)
  accounts[name]
end

#define(name, details) ⇒ Object

Находит, или создает аккаунт с указанным именем



19
20
21
# File 'lib/openbill/registry.rb', line 19

def define(name, details)
  accounts[name] = service.([category, name], details: details)
end

#find(name) ⇒ Object



27
28
29
# File 'lib/openbill/registry.rb', line 27

def find(name)
  [name] || raise(AccountNotFound, name)
end