Class: Openbill::Registry
- Inherits:
-
Object
- Object
- Openbill::Registry
- Defined in:
- lib/openbill/registry.rb
Constant Summary collapse
- DEFAULT_CATEGORY =
:common
- AccountNotFound =
Class.new StandardError
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#define(name, details) ⇒ Object
Находит, или создает аккаунт с указанным именем.
- #find(name) ⇒ Object
-
#initialize(service, category = DEFAULT_CATEGORY) {|_self| ... } ⇒ Registry
constructor
A new instance of Registry.
Constructor Details
#initialize(service, category = DEFAULT_CATEGORY) {|_self| ... } ⇒ Registry
Returns a new instance of Registry.
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
#accounts ⇒ Object (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.account([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 |