Class: TenantsHelper::Tenants
- Inherits:
-
Object
- Object
- TenantsHelper::Tenants
- Defined in:
- lib/tenants_helper/tenants.rb
Instance Method Summary collapse
- #find(id) ⇒ Object
- #find_by(query) ⇒ Object
- #find_by!(query) ⇒ Object
-
#initialize(tenants_config_hash:) ⇒ Tenants
constructor
A new instance of Tenants.
- #name_to_id(name) ⇒ Object
- #valid?(id) ⇒ Boolean
Constructor Details
#initialize(tenants_config_hash:) ⇒ Tenants
Returns a new instance of Tenants.
4 5 6 7 8 9 10 11 12 |
# File 'lib/tenants_helper/tenants.rb', line 4 def initialize(tenants_config_hash:) @tenants = QueryableCollection.create( tenants_config_hash.map { |id, attributes| new_attributes = attributes.rekey Tenant.new(new_attributes.merge(id: id)) }, Tenant.anima.attribute_names ) end |
Instance Method Details
#find(id) ⇒ Object
24 25 26 |
# File 'lib/tenants_helper/tenants.rb', line 24 def find(id) find_by!(id: id) end |
#find_by(query) ⇒ Object
14 15 16 |
# File 'lib/tenants_helper/tenants.rb', line 14 def find_by(query) @tenants.find_by(query) end |
#find_by!(query) ⇒ Object
18 19 20 21 22 |
# File 'lib/tenants_helper/tenants.rb', line 18 def find_by!(query) find_by(query) || fail(ArgumentError, "Could not find Tenant for #{query.inspect}") end |
#name_to_id(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/tenants_helper/tenants.rb', line 32 def name_to_id(name) tenant = find_by(name: name) return nil unless tenant tenant.id end |
#valid?(id) ⇒ Boolean
28 29 30 |
# File 'lib/tenants_helper/tenants.rb', line 28 def valid?(id) !find_by(id: id).nil? end |