Class: Apartment::Privileges::Context
- Inherits:
-
Object
- Object
- Apartment::Privileges::Context
- Defined in:
- lib/apartment/privileges/context.rb
Overview
What a tenant_privilege_policy receives. One instance per phase.
Deliberately not Data.define, though Data is house style for value objects (Migrator::Result, PoolObserver::Sample). This is not a value object: it carries a live connection, which is mutable and meaningless outside the invocation, and Data would give it value equality, hashing and positional decomposition as public semantics. Data also cannot deliver the additive-only promise below — appending a member adds a required positional argument and a required keyword to .new, and Data responds to #deconstruct, so an adopter constructing a context in a unit test or destructuring it positionally would break on a minor release.
Additive-only: new fields arrive as keyword arguments with defaults, and unknown keywords are ignored, so a policy reading attributes off a context Apartment handed it keeps working. Construction is the gem's business.
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#container_name ⇒ Object
readonly
Returns the value of attribute container_name.
-
#db_role ⇒ Object
readonly
Returns the value of attribute db_role.
-
#phase ⇒ Object
readonly
Returns the value of attribute phase.
-
#tenant ⇒ Object
readonly
Returns the value of attribute tenant.
Instance Method Summary collapse
- #after_schema_load? ⇒ Boolean
- #before_schema_load? ⇒ Boolean
-
#initialize(tenant:, container_name:, connection:, db_role:, phase:) ⇒ Context
constructor
A new instance of Context.
-
#quoted_container ⇒ Object
The value every policy needs.
Constructor Details
#initialize(tenant:, container_name:, connection:, db_role:, phase:) ⇒ Context
Returns a new instance of Context.
30 31 32 33 34 35 36 37 |
# File 'lib/apartment/privileges/context.rb', line 30 def initialize(tenant:, container_name:, connection:, db_role:, phase:, **) @tenant = tenant @container_name = container_name @connection = connection @db_role = db_role @phase = phase freeze end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
21 22 23 |
# File 'lib/apartment/privileges/context.rb', line 21 def connection @connection end |
#container_name ⇒ Object (readonly)
Returns the value of attribute container_name.
21 22 23 |
# File 'lib/apartment/privileges/context.rb', line 21 def container_name @container_name end |
#db_role ⇒ Object (readonly)
Returns the value of attribute db_role.
21 22 23 |
# File 'lib/apartment/privileges/context.rb', line 21 def db_role @db_role end |
#phase ⇒ Object (readonly)
Returns the value of attribute phase.
21 22 23 |
# File 'lib/apartment/privileges/context.rb', line 21 def phase @phase end |
#tenant ⇒ Object (readonly)
Returns the value of attribute tenant.
21 22 23 |
# File 'lib/apartment/privileges/context.rb', line 21 def tenant @tenant end |
Instance Method Details
#after_schema_load? ⇒ Boolean
40 |
# File 'lib/apartment/privileges/context.rb', line 40 def after_schema_load? = phase == :after_schema_load |
#before_schema_load? ⇒ Boolean
39 |
# File 'lib/apartment/privileges/context.rb', line 39 def before_schema_load? = phase == :before_schema_load |
#quoted_container ⇒ Object
The value every policy needs. Provided so that copied example code quotes by default rather than interpolating a raw identifier.
44 |
# File 'lib/apartment/privileges/context.rb', line 44 def quoted_container = connection.quote_table_name(container_name) |