class PlaceOS::Model::Zone

Included Modules

Defined in:

placeos-models/zone.cr

Constant Summary

CALLBACKS = {before_save: [:check_playlists, :check_triggers] of Nil, after_save: [:update_triggers] 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: [:destroy_children, :destroy_trigger_instances, :destroy_metadata_and_versions, :destroy_settings_and_versions, :remove_zone] of Nil, after_destroy: [] of Nil}
Log = ::Log.for(self)

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module PlaceOS::Model::Playlist::Checker

check_playlists check_playlists

Instance methods inherited from module PlaceOS::Model::Utilities::MetadataHelper

metadata(name : String | Nil = nil) : Array(Metadata) metadata

Instance methods inherited from module PlaceOS::Model::Utilities::SettingsHelper

all_settings : Hash(YAML::Any, YAML::Any) all_settings, settings : Array(Settings) settings, settings_at(encryption_level : Encryption::Level) settings_at, settings_at?(encryption_level : Encryption::Level) settings_at?, settings_hierarchy : Array(Settings) settings_hierarchy, settings_json : String settings_json

Instance methods inherited from class PlaceOS::Model::ModelBase

after_create after_create, after_destroy after_destroy, after_save after_save, after_update after_update, apply_defaults apply_defaults, assign_attributes(params : HTTP::Params | Hash(String, String) | Tuple(String, String))
assign_attributes(model : PlaceOS::Model::ModelBase)
assign_attributes
assign_attributes
, attributes attributes, attributes_tuple attributes_tuple, before_create before_create, before_destroy before_destroy, before_save before_save, before_update before_update, invoke_props invoke_props, persistent_attributes persistent_attributes, run_create_callbacks(&) run_create_callbacks, run_destroy_callbacks(&) run_destroy_callbacks, run_save_callbacks(&) run_save_callbacks, run_update_callbacks(&) run_update_callbacks

Constructor methods inherited from class PlaceOS::Model::ModelBase

new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
new(pull : JSON::PullParser)
new(rs : DB::ResultSet)
new

Class methods inherited from class PlaceOS::Model::ModelBase

attributes : Array(Symbol) attributes, auto_generate_id : Bool auto_generate_id, from_rs(rs : DB::ResultSet) from_rs, primary_key : Symbol primary_key

Instance methods inherited from module PlaceOS::Model::Associations

format_list_for_postgres(list : Enumerable(String)) : String format_list_for_postgres, reset_associations reset_associations

Class methods inherited from module PlaceOS::Model::Associations

format_list_for_postgres(list : Enumerable(String)) : String format_list_for_postgres

Macros inherited from module PlaceOS::Model::Associations

belongs_to(parent_class, dependent = :none, association_name = nil, foreign_key = nil, presence = false, pk_type = nil, serialize = true) belongs_to, has_many(child_class, collection_name = nil, dependent = :none, foreign_key = nil, serialize = false) has_many, has_one(child_class, dependent = :none, association_name = nil, presence = false) has_one

Constructor Detail

def self.from_json(string_or_io : String | IO, trusted : Bool = false) : self #

def 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">

def self.from_trusted_json(string_or_io : String | IO, root : String) : self #

def self.from_trusted_json(string_or_io : String | IO) : self #

Serialize from a trusted JSON source


def self.from_trusted_yaml(string_or_io : String | IO) : self #

Serialize from a trusted YAML source


def self.from_yaml(string_or_io : String | IO, trusted : Bool = false) : self #

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new(pull : JSON::PullParser) #

[View source]
def self.new(rs : DB::ResultSet) #

def self.new(created_at : Time | ActiveModel::Model::None = ::ActiveModel::Model::None.new, updated_at : Time | ActiveModel::Model::None = ::ActiveModel::Model::None.new, name : String | ActiveModel::Model::None = ::ActiveModel::Model::None.new, description : String | ActiveModel::Model::None = ::ActiveModel::Model::None.new, tags : Set(String) | ActiveModel::Model::None = ::ActiveModel::Model::None.new, location : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, display_name : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, code : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, type : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, count : Int32 | ActiveModel::Model::None = ::ActiveModel::Model::None.new, capacity : Int32 | ActiveModel::Model::None = ::ActiveModel::Model::None.new, map_id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, timezone : Time::Location | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, triggers : Array(String) | ActiveModel::Model::None = ::ActiveModel::Model::None.new, images : Array(String) | ActiveModel::Model::None = ::ActiveModel::Model::None.new, playlists : Array(String) | ActiveModel::Model::None = ::ActiveModel::Model::None.new, place_id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, parent_id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new) #

def self.new(params : HTTP::Params | Hash(String, String) | Tuple(String, String)) #

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


Class Method Detail

def self.attributes : Array(Symbol) #

Returns all attribute keys.


def self.auto_generate_id : Bool #

def self.by_parent_id(id) #

Look up instances of this model dependent on the foreign key


[View source]
def self.changes(id : PrimaryKeyType = 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.


def self.elastic #

def self.from_rs(__temp_706 : DB::ResultSet) #

def self.on_error(err : Exception | IO::Error) #

def self.primary_key : Symbol #

def self.table_name #

def self.with_playlists(ids : Enumerable(String)) #

[View source]
def self.with_tag(tag : String) #

[View source]

Instance Method Detail

def __parent : Zone | Nil #

Association ##############################################################################################


def __parent=(__parent : Zone | Nil) #

Association ##############################################################################################


def after_create #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def after_destroy #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def after_initialize(trusted : Bool) #

def after_save #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def after_update #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def apply_defaults #

Generate code to apply default values


def assign_attributes(created_at : Time | Missing = Missing, updated_at : Time | Missing = Missing, name : String | Missing = Missing, description : String | Missing = Missing, tags : Set(String) | Missing = Missing, location : String | Nil | Missing = Missing, display_name : String | Nil | Missing = Missing, code : String | Nil | Missing = Missing, type : String | Nil | Missing = Missing, count : Int32 | Missing = Missing, capacity : Int32 | Missing = Missing, map_id : String | Nil | Missing = Missing, timezone : Time::Location | Nil | Missing = Missing, triggers : Array(String) | Missing = Missing, images : Array(String) | Missing = Missing, playlists : Array(String) | Missing = Missing, place_id : String | Nil | Missing = Missing, parent_id : String | Nil | Missing = Missing, id : String | Nil | Missing = Missing) #

Assign to multiple attributes.


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

Assign to mulitple attributes via HTTP::Params.


def assign_attributes(model : PlaceOS::Model::Zone) #

Assign to multiple attributes from a model object


def assign_attributes_from_json(json, root : String) #

def assign_attributes_from_json(json) #

def assign_attributes_from_trusted_json(json, root : String) #

def assign_attributes_from_trusted_json(json) #

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


def assign_attributes_from_trusted_yaml(yaml) #

def assign_attributes_from_yaml(yaml) #

Uses the YAML parser as JSON is valid YAML


def attributes #

Returns a Hash of all attribute values


def attributes_tuple #

Returns a NamedTuple of all attribute values.


def before_create #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def before_destroy #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def before_save #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def before_update #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def capacity : Int32 #

#capacity getter


def capacity=(value : Int32) #

#capacity setter


def capacity? : Int32 | Nil #

Could be used as a people capacity


def capacity_assigned? : Bool #

def capacity_change : Tuple(Int32 | Nil, Int32 | Nil) | Nil #

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


def capacity_changed? : Bool #

def capacity_default : Int32 #

#capacity's default value


[View source]
def capacity_present? : Bool #

Could be used as a people capacity


def capacity_was : Int32 | Nil #

def capacity_will_change! : Nil #

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


def changed? #

Check if any attributes have changed.


def changed_attributes #

Returns a Hash with all changed attributes.


def changed_json(io : IO) : Nil #

Serialize the set of changed attributes to JSON.


def changed_json : String #

Serialize the set of changed attributes to JSON.


def changed_persist_attributes #

def changed_yaml(io : IO) : Nil #

Serialize the set of changed attributes to YAML.


def changed_yaml : String #

Serialize the set of changed attributes to YAML.


def children #

[View source]
def clear_changes_information #

Reset changes for all attributes.


def code : String | Nil #

#code getter


def code=(value : String | Nil) #

#code setter


def code_assigned? : Bool #

def code_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def code_changed? : Bool #

def code_default : String | Nil #

#code's default value


[View source]
def code_present? : Bool #

Could be used as floor code


def code_was : String | Nil | Nil #

def code_will_change! : Nil #

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


def count : Int32 #

#count getter


def count=(value : Int32) #

#count setter


def count? : Int32 | Nil #

Could be used as a desk count


def count_assigned? : Bool #

def count_change : Tuple(Int32 | Nil, Int32 | Nil) | Nil #

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


def count_changed? : Bool #

def count_default : Int32 #

#count's default value


[View source]
def count_present? : Bool #

Could be used as a desk count


def count_was : Int32 | Nil #

def count_will_change! : Nil #

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


def created_at : Time #

#created_at getter


def created_at=(value : Time) #

Setters #created_at setter


def created_at? : Time | Nil #

Assign instance variable to correct type


def created_at_assigned? : Bool #

def created_at_change : Tuple(Time | Nil, Time | Nil) | Nil #

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


def created_at_changed? : Bool #

def created_at_default : Time #

#created_at's default value


def created_at_present? : Bool #

def created_at_was : Time | Nil #

def created_at_will_change! : Nil #

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


def description : String #

#description getter


def description=(value : String) #

#description setter


def description? : String | Nil #

Assign instance variable to correct type


def description_assigned? : Bool #

def description_change : Tuple(String | Nil, String | Nil) | Nil #

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


def description_changed? : Bool #

def description_default : String #

#description's default value


[View source]
def description_present? : Bool #

def description_was : String | Nil #

def description_will_change! : Nil #

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


def destroy_children #

def destroy_metadata_and_versions #

Metadata belonging to this zone


def destroy_settings_and_versions #

Encrypted yaml settings


def destroy_trigger_instances #

def display_name : String | Nil #

#display_name getter


def display_name=(value : String | Nil) #

#display_name setter


def display_name_assigned? : Bool #

def display_name_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def display_name_changed? : Bool #

def display_name_default : String | Nil #

#display_name's default value


[View source]
def display_name_present? : Bool #

For display on staff app


def display_name_was : String | Nil | Nil #

def display_name_will_change! : Nil #

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


def id : String | Nil #

#id getter


def id=(value : String | Nil) #

#id setter


def id? : String | Nil | Nil #
Description copied from class PgORM::Base

Same as #id but may return nil when the record hasn't been saved instead of raising.


def id_assigned? : Bool #

def id_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def id_changed? : Bool #

def id_default : String | Nil #

#id's default value


def id_present? : Bool #

def id_was : String | Nil | Nil #

def id_will_change! : Nil #

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


def images : Array(String) #

#images getter


def images=(value : Array(String)) #

#images setter


def images? : Array(String) | Nil #

Assign instance variable to correct type


def images_assigned? : Bool #

def images_change : Tuple(Array(String) | Nil, Array(String) | Nil) | Nil #

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


def images_changed? : Bool #

def images_default : Array(String) #

#images's default value


[View source]
def images_present? : Bool #

def images_was : Array(String) | Nil #

def images_will_change! : Nil #

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


def invoke_props #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


def location : String | Nil #

#location getter


def location=(value : String | Nil) #

#location setter


def location_assigned? : Bool #

def location_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def location_changed? : Bool #

def location_default : String | Nil #

#location's default value


[View source]
def location_present? : Bool #

============================= Additional top level metadata that is fairly common

Geo-location string (lat,long) or any other location


def location_was : String | Nil | Nil #

def location_will_change! : Nil #

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


def map_id : String | Nil #

#map_id getter


def map_id=(value : String | Nil) #

#map_id setter


def map_id_assigned? : Bool #

def map_id_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def map_id_changed? : Bool #

def map_id_default : String | Nil #

#map_id's default value


[View source]
def map_id_present? : Bool #

Map identifier, could be a URL or id


def map_id_was : String | Nil | Nil #

def map_id_will_change! : Nil #

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


def metadata_and_versions #

Metadata belonging to this zone


[View source]
def name : String #

#name getter


def name=(value : String) #

#name setter


def name? : String | Nil #

Assign instance variable to correct type


def name_assigned? : Bool #

def name_change : Tuple(String | Nil, String | Nil) | Nil #

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


def name_changed? : Bool #

def name_default : String #

#name's default value


[View source]
def name_present? : Bool #

def name_was : String | Nil #

def name_will_change! : Nil #

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


def parent : Zone | Nil #

Retrieves the parent relationship


[View source]
def parent! : Zone #

Association ##############################################################################################


[View source]
def parent=(parent : Zone) #

Sets the parent relationship


[View source]
def parent_id : String | Nil #

#parent_id getter


def parent_id=(value : String | Nil) #

#parent_id setter


def parent_id_assigned? : Bool #

def parent_id_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def parent_id_changed? : Bool #

def parent_id_default : String | Nil #

#parent_id's default value


def parent_id_present? : Bool #

Association ##############################################################################################


def parent_id_was : String | Nil | Nil #

def parent_id_will_change! : Nil #

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


def persistent_attributes #

Returns a Hash of all attributes that can be persisted.


def place_id : String | Nil #

#place_id getter


def place_id=(value : String | Nil) #

#place_id setter


def place_id_assigned? : Bool #

def place_id_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def place_id_changed? : Bool #

def place_id_default : String | Nil #

#place_id's default value


[View source]
def place_id_present? : Bool #

def place_id_was : String | Nil | Nil #

def place_id_will_change! : Nil #

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


def playlists : Array(String) #

#playlists getter


def playlists=(value : Array(String)) #

#playlists setter


def playlists? : Array(String) | Nil #

Assign instance variable to correct type


def playlists_assigned? : Bool #

def playlists_change : Tuple(Array(String) | Nil, Array(String) | Nil) | Nil #

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


def playlists_changed? : Bool #

def playlists_default : Array(String) #

#playlists's default value


[View source]
def playlists_present? : Bool #

def playlists_was : Array(String) | Nil #

def playlists_will_change! : Nil #

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


def reset_associations #

Association ##############################################################################################


[View source]
def restore_attributes #

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


def root_zone #

[View source]
def root_zone_id : String #

[View source]
def run_create_callbacks(&) #

Wrap a block with callbacks for the appropriate crud operation


[View source]
def run_destroy_callbacks(&) #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def run_save_callbacks(&) #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def run_update_callbacks(&) #
Description copied from class PlaceOS::Model::ModelBase

Base class for all Engine models


[View source]
def settings_and_versions #

Encrypted yaml settings


[View source]
def settings_hierarchy : Array(Settings) #

[View source]
def systems #

Find systems


[View source]
def table_name #

def tags : Set(String) #

#tags getter


def tags=(value : Set(String)) #

#tags setter


def tags? : Set(String) | Nil #

Assign instance variable to correct type


def tags_assigned? : Bool #

def tags_change : Tuple(Set(String) | Nil, Set(String) | Nil) | Nil #

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


def tags_changed? : Bool #

def tags_default : Set(String) #

#tags's default value


[View source]
def tags_present? : Bool #

def tags_was : Set(String) | Nil #

def tags_will_change! : Nil #

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


def timezone : Time::Location | Nil #

#timezone getter


def timezone=(value : Time::Location | Nil) #

#timezone setter


def timezone_assigned? : Bool #

def timezone_change : Tuple(Time::Location | Nil | Nil, Time::Location | Nil | Nil) | Nil #

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


def timezone_changed? : Bool #

def timezone_default : Time::Location | Nil #

#timezone's default value


[View source]
def timezone_present? : Bool #

Timezone


def timezone_was : Time::Location | Nil | Nil #

def timezone_will_change! : Nil #

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


def trigger_data : Array(Trigger) #

Looks up the triggers attached to the zone


[View source]
def trigger_instances #

[View source]
def triggers : Array(String) #

#triggers getter


def triggers=(value : Array(String)) #

#triggers setter


def triggers? : Array(String) | Nil #

Assign instance variable to correct type


def triggers_assigned? : Bool #

def triggers_change : Tuple(Array(String) | Nil, Array(String) | Nil) | Nil #

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


def triggers_changed? : Bool #

def triggers_default : Array(String) #

#triggers's default value


[View source]
def triggers_present? : Bool #

def triggers_was : Array(String) | Nil #

def triggers_will_change! : Nil #

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


def type : String | Nil #

#type getter


def type=(value : String | Nil) #

#type setter


def type_assigned? : Bool #

def type_change : Tuple(String | Nil | Nil, String | Nil | Nil) | Nil #

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


def type_changed? : Bool #

def type_default : String | Nil #

#type's default value


[View source]
def type_present? : Bool #

Could be used as floor type


def type_was : String | Nil | Nil #

def type_will_change! : Nil #

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


def updated_at : Time #

#updated_at getter


def updated_at=(value : Time) #

#updated_at setter


def updated_at? : Time | Nil #

Assign instance variable to correct type


def updated_at_assigned? : Bool #

def updated_at_change : Tuple(Time | Nil, Time | Nil) | Nil #

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


def updated_at_changed? : Bool #

def updated_at_default : Time #

#updated_at's default value


def updated_at_present? : Bool #

def updated_at_was : Time | Nil #

def updated_at_will_change! : Nil #

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


def validate_nilability #

Validate that all non-nillable fields have values.