class

PlaceOS::Model::BookingInstance

Inherits PlaceOS::Model::Timestamps < PlaceOS::Model::Scope < PlaceOS::Model::Associations < PlaceOS::Model::ModelWithAutoKey < Neuroplastic < PgORM::Base < PgORM::Validators < PgORM::Table < PgORM::Persistence < PgORM::Associations < ActiveModel::Callbacks < ActiveModel::Validation < ActiveModel::Model < DB::Mappable < DB::Serializable < YAML::Serializable < JSON::Serializable < Reference < Object

Constants

CALLBACKS = { before_save: [:update_assets, :update_history] of Nil, after_save: [] of Nil, before_create: [do self.created_at = self.updated_at = Time.utc end] of Nil, after_create: [] of Nil, before_update: [do self.updated_at = Time.utc end] of Nil, after_update: [] of Nil, before_destroy: [] of Nil, after_destroy: [] of Nil, }
Log = ::Log.for(self)
PRIMARY_KEY_TYPES = {:id => (Int64 | Nil)} of Nil => Nil

macro level key => type

PRIMARY_KEYS = [{:id}]

Constructors

from_json(string_or_io : String | IO, trusted : Bool = false) : self
from_json(string_or_io : String | IO, root : String, trusted : Bool = false) : self

Deserializes the given JSON in string_or_io into an instance of self, assuming the JSON consists of an JSON object with key root, and whose value is the value to deserialize. Will not deserialise from fields with mass_assign: false

class User < ActiveModel::Model
  attribute name : String
  attribute google_id : UUID, mass_assign: false
end

User.from_json(%({"main": {"name": "Jason", "google_id": "f6f70bfb-c882-446d-8758-7ce47db39620"}}), root: "main") # => #<User:0x103131b20 @name="Jason">
from_trusted_json(string_or_io : String | IO, root : String) : self
from_trusted_json(string_or_io : String | IO) : self

Serialize from a trusted JSON source

from_trusted_yaml(string_or_io : String | IO) : self

Serialize from a trusted YAML source

from_yaml(string_or_io : String | IO, trusted : Bool = false) : self
new(rs : DB::ResultSet)
new(instance_start : Int64 | ActiveModel::Model::None = ::ActiveModel::Model::None.new, tenant_id : Int64 | ActiveModel::Model::None = ::ActiveModel::Model::None.new, booking_start : Int64 | ActiveModel::Model::None = ::ActiveModel::Model::None.new, booking_end : Int64 | ActiveModel::Model::None = ::ActiveModel::Model::None.new, checked_in : Bool | ActiveModel::Model::None = ::ActiveModel::Model::None.new, checked_in_at : Int64 | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, checked_out_at : Int64 | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, deleted : Bool | ActiveModel::Model::None = ::ActiveModel::Model::None.new, deleted_at : Int64 | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, process_state : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, extension_data : JSON::Any | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, history : Array(PlaceOS::Model::Booking::History) | ActiveModel::Model::None = ::ActiveModel::Model::None.new, utm_source : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, approved : Bool | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, approved_at : Int64 | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, rejected : Bool | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, rejected_at : Int64 | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, approver_id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, approver_name : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, approver_email : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, asset_id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, asset_ids : Array(String) | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, id : Int64 | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, created_at : Time | ActiveModel::Model::None = ::ActiveModel::Model::None.new, updated_at : Time | ActiveModel::Model::None = ::ActiveModel::Model::None.new)

Initialize PlaceOS::Model::BookingInstance from HTTP::Params.

Class methods

attributes

Returns all attribute keys.

by_tenant(tenant_id)
Source
changes(id : Int64 | Nil | Nil = nil) : ChangeFeed

Changefeed at row (if id passed) or whole table level. Returns a ChangeFeed instance which can be used to invoke async callbacks via on or use blocking Iterator via each method.

elastic
from_rs(__temp_2301 : DB::ResultSet)
on_error(err : Exception | IO::Error)
primary_key

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

Source
table_name

Instance methods

after_create

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

after_destroy

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

after_initialize(trusted : Bool)
after_save

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

after_update

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

apply_defaults

Generate code to apply default values

approved

approved getter

approved=(value : Bool | Nil)

approved setter

approved_assigned?
approved_at

approved_at getter

approved_at=(value : Int64 | Nil)

approved_at setter

approved_at_assigned?
approved_at_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

approved_at_changed?
approved_at_default

approved_at's default value

Source
approved_at_present?
approved_at_removed?
approved_at_was
approved_at_will_change!

Include approved_at in the set of changed attributes, whether it has changed or not.

approved_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

approved_changed?
approved_default

approved's default value

Source
approved_present?

custom approval state, nil fields inherit from the parent booking. if either approved or rejected is set, all the approval fields are considered overridden as a group (see #hydrate_booking)

approved_removed?
approved_was
approved_will_change!

Include approved in the set of changed attributes, whether it has changed or not.

approver_email

approver_email getter

approver_email=(value : String | Nil)

approver_email setter

approver_email_assigned?
approver_email_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

approver_email_changed?
approver_email_default

approver_email's default value

Source
approver_email_present?
approver_email_removed?
approver_email_was
approver_email_will_change!

Include approver_email in the set of changed attributes, whether it has changed or not.

approver_id

approver_id getter

approver_id=(value : String | Nil)

approver_id setter

approver_id_assigned?
approver_id_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

approver_id_changed?
approver_id_default

approver_id's default value

Source
approver_id_present?
approver_id_removed?
approver_id_was
approver_id_will_change!

Include approver_id in the set of changed attributes, whether it has changed or not.

approver_name

approver_name getter

approver_name=(value : String | Nil)

approver_name setter

approver_name_assigned?
approver_name_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

approver_name_changed?
approver_name_default

approver_name's default value

Source
approver_name_present?
approver_name_removed?
approver_name_was
approver_name_will_change!

Include approver_name in the set of changed attributes, whether it has changed or not.

asset_id

asset_id getter

asset_id=(value : String | Nil)

asset_id setter

asset_id_assigned?
asset_id_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

asset_id_changed?
asset_id_default

asset_id's default value

Source
asset_id_present?

custom asset allocation, nil inherits the parent booking assets

asset_id_removed?
asset_id_was
asset_id_will_change!

Include asset_id in the set of changed attributes, whether it has changed or not.

asset_ids

asset_ids getter

asset_ids=(vals : Array(String) | Nil)
Source
asset_ids=(value : Array(String) | Nil)

asset_ids setter

asset_ids_assigned?
asset_ids_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

asset_ids_changed?
asset_ids_default

asset_ids's default value

Source
asset_ids_present?
asset_ids_removed?
asset_ids_was
asset_ids_will_change!

Include asset_ids in the set of changed attributes, whether it has changed or not.

assign_attributes(instance_start : Int64 | Missing = Missing, tenant_id : Int64 | Missing = Missing, booking_start : Int64 | Missing = Missing, booking_end : Int64 | Missing = Missing, checked_in : Bool | Missing = Missing, checked_in_at : Int64 | Nil | Missing = Missing, checked_out_at : Int64 | Nil | Missing = Missing, deleted : Bool | Missing = Missing, deleted_at : Int64 | Nil | Missing = Missing, process_state : String | Nil | Missing = Missing, extension_data : JSON::Any | Nil | Missing = Missing, history : Array(PlaceOS::Model::Booking::History) | Missing = Missing, utm_source : String | Nil | Missing = Missing, approved : Bool | Nil | Missing = Missing, approved_at : Int64 | Nil | Missing = Missing, rejected : Bool | Nil | Missing = Missing, rejected_at : Int64 | Nil | Missing = Missing, approver_id : String | Nil | Missing = Missing, approver_name : String | Nil | Missing = Missing, approver_email : String | Nil | Missing = Missing, asset_id : String | Nil | Missing = Missing, asset_ids : Array(String) | Nil | Missing = Missing, id : Int64 | Nil | Missing = Missing, created_at : Time | Missing = Missing, updated_at : Time | Missing = Missing)

Assign to multiple attributes.

assign_attributes(params : HTTP::Params | Hash(String, String) | Tuple(String, String))

Assign to multiple attributes via HTTP::Params.

assign_attributes(model : PlaceOS::Model::BookingInstance)

Assign to multiple attributes from a model object

assign_attributes_from_json(json, root : String)
assign_attributes_from_json(json)
assign_attributes_from_trusted_json(json, root : String)
assign_attributes_from_trusted_json(json)

Assign each field from JSON if field exists in JSON and has changed in model

assign_attributes_from_trusted_yaml(yaml)
assign_attributes_from_yaml(yaml)

Uses the YAML parser as JSON is valid YAML

attributes

Returns a Hash of all attribute values

attributes_tuple

Returns a NamedTuple of all attribute values.

before_create

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

before_destroy

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

before_save

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

before_update

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

booking_end

booking_end getter

booking_end=(value : Int64)

booking_end setter

booking_end?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

booking_end_assigned?
booking_end_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

booking_end_changed?
booking_end_default

booking_end's default value

Source
booking_end_present?
booking_end_removed?
booking_end_was
booking_end_will_change!

Include booking_end in the set of changed attributes, whether it has changed or not.

booking_start

booking_start getter

booking_start=(value : Int64)

booking_start setter

booking_start?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

booking_start_assigned?
booking_start_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

booking_start_changed?
booking_start_default

booking_start's default value

Source
booking_start_present?

the new start and end times

booking_start_removed?
booking_start_was
booking_start_will_change!

Include booking_start in the set of changed attributes, whether it has changed or not.

changed?

Check if any attributes have changed.

changed_attributes

Returns a Hash with all changed attributes.

changed_json(io : IO) : Nil

Serialize the set of changed attributes to JSON.

changed_json

Serialize the set of changed attributes to JSON.

changed_persist_attributes
changed_yaml(io : IO) : Nil

Serialize the set of changed attributes to YAML.

changed_yaml

Serialize the set of changed attributes to YAML.

checked_in

checked_in getter

checked_in=(value : Bool)

checked_in setter

checked_in?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

checked_in_assigned?
checked_in_at

checked_in_at getter

checked_in_at=(value : Int64 | Nil)

checked_in_at setter

checked_in_at_assigned?
checked_in_at_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

checked_in_at_changed?
checked_in_at_default

checked_in_at's default value

Source
checked_in_at_present?
checked_in_at_removed?
checked_in_at_was
checked_in_at_will_change!

Include checked_in_at in the set of changed attributes, whether it has changed or not.

checked_in_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

checked_in_changed?
checked_in_default

checked_in's default value

Source
checked_in_present?
checked_in_removed?
checked_in_was
checked_in_will_change!

Include checked_in in the set of changed attributes, whether it has changed or not.

checked_out_at

checked_out_at getter

checked_out_at=(value : Int64 | Nil)

checked_out_at setter

checked_out_at_assigned?
checked_out_at_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

checked_out_at_changed?
checked_out_at_default

checked_out_at's default value

Source
checked_out_at_present?
checked_out_at_removed?
checked_out_at_was
checked_out_at_will_change!

Include checked_out_at in the set of changed attributes, whether it has changed or not.

clear_changes_information

Reset changes for all attributes.

created_at

created_at getter

created_at=(value : Time)

created_at setter

created_at?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

created_at_assigned?
created_at_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

created_at_changed?
created_at_default

created_at's default value

created_at_present?
created_at_removed?
created_at_was
created_at_will_change!

Include created_at in the set of changed attributes, whether it has changed or not.

current_history(state : Booking::State) : Array(History)

An occurrence keeps its own history: Booking#save! delegates to as_instance.save!, so the parent's before_save (and the current_history it builds) never runs for an instance. Without this the occurrence records no transitions at all and the utm_source behind them is lost.

Mirrors Booking#current_history. State comes from the hydrated booking -- that is exactly what the API presents for this occurrence, so its state is the one the history should record, and it avoids duplicating the state machine.

Source
deleted

deleted getter

deleted=(value : Bool)

deleted setter

deleted?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

deleted_assigned?
deleted_at

deleted_at getter

deleted_at=(value : Int64 | Nil)

deleted_at setter

deleted_at_assigned?
deleted_at_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

deleted_at_changed?
deleted_at_default

deleted_at's default value

Source
deleted_at_present?
deleted_at_removed?
deleted_at_was
deleted_at_will_change!

Include deleted_at in the set of changed attributes, whether it has changed or not.

deleted_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

deleted_changed?
deleted_default

deleted's default value

Source
deleted_present?
deleted_removed?
deleted_was
deleted_will_change!

Include deleted in the set of changed attributes, whether it has changed or not.

extension_data

extension_data getter

extension_data=(value : JSON::Any | Nil)

extension_data setter

extension_data_assigned?
extension_data_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

extension_data_changed?
extension_data_default

extension_data's default value

Source
extension_data_present?
extension_data_removed?
extension_data_was
extension_data_will_change!

Include extension_data in the set of changed attributes, whether it has changed or not.

history

history getter

history setter

history?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

history_assigned?
history_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

history_changed?
history_default

history's default value

Source
history_present?
history_removed?
history_was
history_will_change!

Include history in the set of changed attributes, whether it has changed or not.

hydrate_booking(main : Booking = parent_booking) : Booking

returns a booking object that represents this instance

Source
id

id getter

id=(value : Int64 | Nil)

id setter

id?
id_assigned?
id_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

id_changed?
id_default

id's default value

id_present?
id_removed?
id_was
id_will_change!

Include id in the set of changed attributes, whether it has changed or not.

instance_start

instance_start getter

instance_start=(value : Int64)

Setters instance_start setter

instance_start?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

instance_start_assigned?
instance_start_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

instance_start_changed?
instance_start_default

instance_start's default value

Source
instance_start_present?

the original starting time of the instance

instance_start_removed?
instance_start_was
instance_start_will_change!

Include instance_start in the set of changed attributes, whether it has changed or not.

invoke_props

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

parent_booking

property so we can set this if we've already fetched the parent

Source
parent_booking=(parent_booking : Booking)

property so we can set this if we've already fetched the parent

Source
persistent_attributes

Returns a Hash of all attributes that can be persisted.

primary_key

Base class for all models which have auto-generated bigint as pk and doesn't require string based auto generated pk

Source
primary_key_hash
process_state

process_state getter

process_state=(value : String | Nil)

process_state setter

process_state_assigned?
process_state_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

process_state_changed?
process_state_default

process_state's default value

Source
process_state_present?
process_state_removed?
process_state_was
process_state_will_change!

Include process_state in the set of changed attributes, whether it has changed or not.

rejected

rejected getter

rejected=(value : Bool | Nil)

rejected setter

rejected_assigned?
rejected_at

rejected_at getter

rejected_at=(value : Int64 | Nil)

rejected_at setter

rejected_at_assigned?
rejected_at_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

rejected_at_changed?
rejected_at_default

rejected_at's default value

Source
rejected_at_present?
rejected_at_removed?
rejected_at_was
rejected_at_will_change!

Include rejected_at in the set of changed attributes, whether it has changed or not.

rejected_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

rejected_changed?
rejected_default

rejected's default value

Source
rejected_present?
rejected_removed?
rejected_was
rejected_will_change!

Include rejected in the set of changed attributes, whether it has changed or not.

restore_attributes

Reset each attribute to their previous values and clears all changes.

skip_clash_check

transient flag (never (de)serialised, so API clients cannot set it): set by Booking#as_instance when the caller has already run an explicit clash check, so save! does not redundantly re-run it.

Source
skip_clash_check=(skip_clash_check : Bool)

transient flag (never (de)serialised, so API clients cannot set it): set by Booking#as_instance when the caller has already run an explicit clash check, so save! does not redundantly re-run it.

Source
slot_changed?

the clash validation only needs to run when the booked slot itself (time or asset) changes. approving, rejecting or checking in an existing instance must not be blocked by a clash it did not introduce.

Source
table_name
tenant_id

tenant_id getter

tenant_id=(value : Int64)

tenant_id setter

tenant_id?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

tenant_id_assigned?
tenant_id_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

tenant_id_changed?
tenant_id_default

tenant_id's default value

Source
tenant_id_present?
tenant_id_removed?
tenant_id_was
tenant_id_will_change!

Include tenant_id in the set of changed attributes, whether it has changed or not.

unique_ids?
Source
update_assets

keep the custom asset_id and asset_ids in sync, mirroring Booking#update_assets but with nil meaning inherit from the parent

Source
updated_at

updated_at getter

updated_at=(value : Time)

updated_at setter

updated_at?

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

updated_at_assigned?
updated_at_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

updated_at_changed?
updated_at_default

updated_at's default value

updated_at_present?
updated_at_removed?
updated_at_was
updated_at_will_change!

Include updated_at in the set of changed attributes, whether it has changed or not.

utm_source

Accessors for attributes without JSON mapping

utm_source=(value : String | Nil)

utm_source setter

utm_source=(utm_source)

Accessors for attributes without JSON mapping

utm_source_assigned?
utm_source_change

Returns a Tuple of the previous and the current value of an instance variable if it has changed

utm_source_changed?
utm_source_default

utm_source's default value

Source
utm_source_present?

transient, mirrors Booking#utm_source -- recorded against the history entry of the transition it caused, never persisted as a column of its own

utm_source_removed?
utm_source_was
utm_source_will_change!

Include utm_source in the set of changed attributes, whether it has changed or not.

validate_nilability

Validate that all non-nillable fields have values.

Macros

scope(name, &block)

Nested types