Class: ActiveZone::Provider::ZoneCollection Abstract
- Inherits:
-
Object
- Object
- ActiveZone::Provider::ZoneCollection
- Includes:
- Enumerable
- Defined in:
- lib/active_zone/provider/zone_collection.rb
Overview
Subclass and override to create a queryable zone collection
A queryable array-like class representing a collection of Zone at a provider
Instance Attribute Summary collapse
-
#provider ⇒ Provider
readonly
Provider the ZoneCollection is bound to.
-
#set ⇒ Array?
Set of names in the ZoneCollection.
Instance Method Summary collapse
-
#[](i) ⇒ Zone
abstract
Get nth value in collection.
-
#destroy_all ⇒ nil
abstract
Destroy all zones in this collection.
-
#each {|Zone| ... } ⇒ Object
abstract
Iterate over the zones at the provider.
-
#find(name) ⇒ Zone
abstract
Find a zone by name.
-
#find_by(**attributes) ⇒ Zone
abstract
Find a zone by attribute in this collection.
-
#find_or_create_by(**attributes) ⇒ Zone
Find a zone by name inside this collection, if not found then create it.
-
#initialize(provider, set = nil) ⇒ Object
constructor
Initialize new ZoneCollection.
-
#upsert(name) ⇒ Zone
Update a zone by name in this collection, if not found then create it.
Constructor Details
#initialize(provider, set = nil) ⇒ Object
Initialize new ZoneCollection
19 20 21 22 |
# File 'lib/active_zone/provider/zone_collection.rb', line 19 def initialize(provider, set = nil) @provider = provider @set = set end |
Instance Attribute Details
#provider ⇒ Provider (readonly)
Provider the ZoneCollection is bound to
9 10 11 |
# File 'lib/active_zone/provider/zone_collection.rb', line 9 def provider @provider end |
#set ⇒ Array?
Set of names in the ZoneCollection
13 14 15 |
# File 'lib/active_zone/provider/zone_collection.rb', line 13 def set @set end |
Instance Method Details
#[](i) ⇒ Zone
Override and get the nth value in the set at the provider
Get nth value in collection
76 77 78 |
# File 'lib/active_zone/provider/zone_collection.rb', line 76 def [](i) raise NotImplementedError end |
#destroy_all ⇒ nil
Override and destroy all zones in the set at the provider
Destroy all zones in this collection
36 37 38 |
# File 'lib/active_zone/provider/zone_collection.rb', line 36 def destroy_all raise NotImplementedError end |
#each {|Zone| ... } ⇒ Object
Override and yield all zones in the set at the provider
Iterate over the zones at the provider
28 29 30 |
# File 'lib/active_zone/provider/zone_collection.rb', line 28 def each(&block) raise NotImplementedError end |
#find(name) ⇒ Zone
Override and find the first zone by name in the set at the provider
Find a zone by name
44 45 46 |
# File 'lib/active_zone/provider/zone_collection.rb', line 44 def find(name) raise NotImplementedError end |
#find_by(**attributes) ⇒ Zone
Override and find the first zone that matches the provided attributes in the set at the provider
Find a zone by attribute in this collection
53 54 55 |
# File 'lib/active_zone/provider/zone_collection.rb', line 53 def find_by(**attributes) raise NotImplementedError end |
#find_or_create_by(**attributes) ⇒ Zone
Find a zone by name inside this collection, if not found then create it
60 61 62 |
# File 'lib/active_zone/provider/zone_collection.rb', line 60 def find_or_create_by(**attributes) find_by(attributes) || provider.Zone.create(attributes) end |
#upsert(name) ⇒ Zone
Update a zone by name in this collection, if not found then create it
67 68 69 70 |
# File 'lib/active_zone/provider/zone_collection.rb', line 67 def upsert(name) z = find_or_create_by(name:) z.update(attributes) end |