class PlaceOS::Model::Settings
- PlaceOS::Model::Settings
- PlaceOS::Model::ModelBase
- PgORM::Base
- ActiveModel::Model
- Reference
- Object
Included Modules
- PlaceOS::Model::Timestamps
- PlaceOS::Model::Utilities::LastModified
- PlaceOS::Model::Utilities::Versions
Defined in:
placeos-models/settings.crConstant Summary
-
CALLBACKS =
{before_save: [:set_modified_by, :parse_parent_type, :build_keys, :encrypt_settings] of Nil, after_save: [:clear_modifier, :__create_version__, :cleanup_history] 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_settings] of Nil, after_destroy: [] of Nil}
-
Log =
::Log.for(self)
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. - .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(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
- .new(pull : JSON::PullParser)
- .new(rs : DB::ResultSet)
- .new(created_at : Time | ActiveModel::Model::None = ::ActiveModel::Model::None.new, updated_at : Time | ActiveModel::Model::None = ::ActiveModel::Model::None.new, modified_by_id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, settings_id : String | Nil | ActiveModel::Model::None = ::ActiveModel::Model::None.new, encryption_level : PlaceOS::Encryption::Level | ActiveModel::Model::None = ::ActiveModel::Model::None.new, settings_string : String | ActiveModel::Model::None = ::ActiveModel::Model::None.new, keys : Array(String) | ActiveModel::Model::None = ::ActiveModel::Model::None.new, parent_type : PlaceOS::Model::Settings::ParentType | 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)
-
.new(params : HTTP::Params | Hash(String, String) | Tuple(String, String))
Initialize PlaceOS::Model::Settings from
HTTP::Params
.
Class Method Summary
-
.attributes : Array(Symbol)
Returns all attribute keys.
- .auto_generate_id : Bool
-
.by_parent_id(id)
Look up instances of this model dependent on the foreign key
-
.changes(id : PrimaryKeyType = nil) : ChangeFeed
Changefeed at row (if
#id
passed) or whole table level. - .elastic
-
.for_parent(parent_ids : String | Array(String), &) : Array(self)
Get
Settings
for given parent id/s -
.for_parent(parent_ids : String | Array(String)) : Array(self)
Get
Settings
for given parent id/s - .from_rs(__temp_712 : DB::ResultSet)
-
.get_setting_for?(user : Model::User, key : String, settings : Array(Settings) = [] of Settings) : YAML::Any | Nil
Look up a settings key, if it exists and the user has the correct privilege
- .has_privilege?(user : User, encryption_level : Encryption::Level)
-
.master_settings_query(offset : Int32 = 0, limit : Int32 = 100, &)
Query on main settings records
-
.master_settings_query_count(&)
Count of records returned by query on main settings records
-
.master_settings_raw_query(count : Bool = false, &)
Query on main settings records
- .on_error(err : Exception | IO::Error)
- .primary_key : Symbol
-
.query(ids : String | Array(String))
Query all settings under
#parent_id
- .table_name
Instance Method Summary
- #__control_system : ControlSystem | Nil
- #__control_system=(__control_system : ControlSystem | Nil)
- #__driver : Driver | Nil
- #__driver=(__driver : Driver | Nil)
- #__mod : Module | Nil
- #__mod=(__mod : Module | Nil)
- #__modified_by : User | Nil
- #__modified_by=(__modified_by : User | Nil)
- #__zone : Zone | Nil
- #__zone=(__zone : Zone | Nil)
-
#after_create
Base class for all Engine models
-
#after_destroy
Base class for all Engine models
- #after_initialize(trusted : Bool)
-
#after_save
Base class for all Engine models
-
#after_update
Base class for all Engine models
-
#any(user : User) : Hash(YAML::Any, YAML::Any) | Nil
Decrypts settings for a user, merges into single JSON object
-
#any : Hash(YAML::Any, YAML::Any)
Decrypts settings, merges into single JSON object
-
#apply_defaults
Generate code to apply default values
-
#assign_attributes(created_at : Time | Missing = Missing, updated_at : Time | Missing = Missing, modified_by_id : String | Nil | Missing = Missing, settings_id : String | Nil | Missing = Missing, encryption_level : PlaceOS::Encryption::Level | Missing = Missing, settings_string : String | Missing = Missing, keys : Array(String) | Missing = Missing, parent_type : PlaceOS::Model::Settings::ParentType | Missing = Missing, parent_id : String | Nil | Missing = Missing, id : String | Nil | Missing = Missing)
Assign to multiple attributes.
-
#assign_attributes(params : HTTP::Params | Hash(String, String) | Tuple(String, String))
Assign to mulitple attributes via
HTTP::Params
. -
#assign_attributes(model : PlaceOS::Model::Settings)
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 Engine models
-
#before_destroy
Base class for all Engine models
-
#before_save
Base class for all Engine models
-
#before_update
Base class for all Engine models
-
#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 : String
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 : String
Serialize the set of changed attributes to YAML.
-
#clear_changes_information
Reset changes for all attributes.
-
#control_system : ControlSystem | Nil
Retrieves the parent relationship
- #control_system! : ControlSystem
-
#control_system=(parent : ControlSystem)
Sets the parent relationship
-
#created_at : Time
#created_at
getter -
#created_at=(value : Time)
Setters
#created_at
setter -
#created_at? : Time | Nil
Assign instance variable to correct type
- #created_at_assigned? : Bool
-
#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
- #created_at_changed? : Bool
-
#created_at_default : Time
#created_at
's default value - #created_at_present? : Bool
- #created_at_was : Time | Nil
-
#created_at_will_change! : Nil
Include
#created_at
in the set of changed attributes, whether it has changed or not. -
#decrypt_for(user) : String
Decrypts (if user has correct privilege) and returns the settings string
-
#decrypt_for!(user)
Decrypts the model's settings string dependent on user privileges
-
#dependent_modules : Array(Model::Module)
Locate the modules that will be affected by the change of this setting
- #destroy_settings
-
#driver : Driver | Nil
Retrieves the parent relationship
- #driver! : Driver
-
#driver=(parent : Driver)
Sets the parent relationship
-
#encrypt!
Encrypt in place
-
#encryption_level : PlaceOS::Encryption::Level
#encryption_level
getter -
#encryption_level=(value : PlaceOS::Encryption::Level)
#encryption_level
setter -
#encryption_level? : PlaceOS::Encryption::Level | Nil
Assign instance variable to correct type
- #encryption_level_assigned? : Bool
-
#encryption_level_change : Tuple(PlaceOS::Encryption::Level | Nil, PlaceOS::Encryption::Level | Nil) | Nil
Returns a Tuple of the previous and the current value of an instance variable if it has changed
- #encryption_level_changed? : Bool
-
#encryption_level_default : Encryption::Level
#encryption_level
's default value - #encryption_level_present? : Bool
- #encryption_level_was : PlaceOS::Encryption::Level | Nil
-
#encryption_level_will_change! : Nil
Include
#encryption_level
in the set of changed attributes, whether it has changed or not. -
#get_setting_for?(user, setting) : YAML::Any | Nil
Decrypt and pick off the setting
-
#has_key_for?(user, key)
Check if top-level settings key present for the supplied user
-
#history(offset : Int32 = 0, limit : Int32 = 10, &)
Get version history
-
#history(offset : Int32 = 0, limit : Int32 = 10)
Get version history
-
#history_count
Return the number of versions for the main record.
-
#id : String | Nil
#id
getter -
#id=(value : String | Nil)
#id
setter -
#id? : String | Nil | Nil
Same as
#id
but may returnnil
when the record hasn't been saved instead of raising. - #id_assigned? : Bool
-
#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
- #id_changed? : Bool
-
#id_default : String | Nil
#id
's default value - #id_present? : Bool
- #id_was : String | Nil | Nil
-
#id_will_change! : Nil
Include
#id
in the set of changed attributes, whether it has changed or not. -
#invoke_props
Base class for all Engine models
-
#is_encrypted? : Bool
Determine if setting_string is encrypted
-
#is_version? : Bool
If a PlaceOS::Model::Settings has a parent, it's a version
-
#keys : Array(String)
#keys
getter -
#keys=(value : Array(String))
#keys
setter -
#keys? : Array(String) | Nil
Assign instance variable to correct type
- #keys_assigned? : Bool
-
#keys_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
- #keys_changed? : Bool
-
#keys_default : Array(String)
#keys
's default value - #keys_present? : Bool
- #keys_was : Array(String) | Nil
-
#keys_will_change! : Nil
Include
#keys
in the set of changed attributes, whether it has changed or not. -
#mod : Module | Nil
Retrieves the parent relationship
- #mod! : Module
-
#mod=(parent : Module)
Sets the parent relationship
-
#modified_by : User | Nil
Get cached child or attempt to load an associated modified_by
- #modified_by! : User
- #modified_by=(user)
-
#modified_by_id : String | Nil
#modified_by_id
getter -
#modified_by_id=(value : String | Nil)
#modified_by_id
setter - #modified_by_id_assigned? : Bool
-
#modified_by_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
- #modified_by_id_changed? : Bool
-
#modified_by_id_default : String | Nil
#modified_by_id
's default value - #modified_by_id_present? : Bool
- #modified_by_id_was : String | Nil | Nil
-
#modified_by_id_will_change! : Nil
Include
#modified_by_id
in the set of changed attributes, whether it has changed or not. -
#parent
Retrieve the parent relation
- #parent=(parent : Union(Zone, ControlSystem, Driver, Module))
-
#parent_id : String | Nil
#parent_id
getter -
#parent_id=(value : String | Nil)
#parent_id
setter - #parent_id_assigned? : Bool
-
#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
- #parent_id_changed? : Bool
-
#parent_id_default : String | Nil
#parent_id
's default value - #parent_id_present? : Bool
- #parent_id_was : String | Nil | Nil
-
#parent_id_will_change! : Nil
Include
#parent_id
in the set of changed attributes, whether it has changed or not. -
#parent_type : PlaceOS::Model::Settings::ParentType
#parent_type
getter -
#parent_type=(value : PlaceOS::Model::Settings::ParentType)
#parent_type
setter -
#parent_type? : PlaceOS::Model::Settings::ParentType | Nil
Assign instance variable to correct type
- #parent_type_assigned? : Bool
-
#parent_type_change : Tuple(PlaceOS::Model::Settings::ParentType | Nil, PlaceOS::Model::Settings::ParentType | Nil) | Nil
Returns a Tuple of the previous and the current value of an instance variable if it has changed
- #parent_type_changed? : Bool
-
#parent_type_default : ParentType
#parent_type
's default value - #parent_type_present? : Bool
- #parent_type_was : PlaceOS::Model::Settings::ParentType | Nil
-
#parent_type_will_change! : Nil
Include
#parent_type
in the set of changed attributes, whether it has changed or not. -
#persistent_attributes
Returns a
Hash
of all attributes that can be persisted. - #reset_associations
-
#restore_attributes
Reset each attribute to their previous values and clears all changes.
-
#run_create_callbacks(&)
Wrap a block with callbacks for the appropriate crud operation
-
#run_destroy_callbacks(&)
Base class for all Engine models
-
#run_save_callbacks(&)
Base class for all Engine models
-
#run_update_callbacks(&)
Base class for all Engine models
- #settings
-
#settings_id : String | Nil
#settings_id
getter -
#settings_id=(value : String | Nil)
#settings_id
setter - #settings_id_assigned? : Bool
-
#settings_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
- #settings_id_changed? : Bool
-
#settings_id_default : String | Nil
#settings_id
's default value -
#settings_id_present? : Bool
Associate with main version
- #settings_id_was : String | Nil | Nil
-
#settings_id_will_change! : Nil
Include
#settings_id
in the set of changed attributes, whether it has changed or not. -
#settings_json
Decrypts settings, encodes as a json object
-
#settings_string : String
#settings_string
getter -
#settings_string=(value : String)
#settings_string
setter -
#settings_string? : String | Nil
Assign instance variable to correct type
- #settings_string_assigned? : Bool
-
#settings_string_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
- #settings_string_changed? : Bool
-
#settings_string_default : String
#settings_string
's default value - #settings_string_present? : Bool
- #settings_string_was : String | Nil
-
#settings_string_will_change! : Nil
Include
#settings_string
in the set of changed attributes, whether it has changed or not. - #table_name
-
#updated_at : Time
#updated_at
getter -
#updated_at=(value : Time)
#updated_at
setter -
#updated_at? : Time | Nil
Assign instance variable to correct type
- #updated_at_assigned? : Bool
-
#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
- #updated_at_changed? : Bool
-
#updated_at_default : Time
#updated_at
's default value - #updated_at_present? : Bool
- #updated_at_was : Time | Nil
-
#updated_at_will_change! : Nil
Include
#updated_at
in the set of changed attributes, whether it has changed or not. -
#validate_nilability
Validate that all non-nillable fields have values.
-
#zone : Zone | Nil
Retrieves the parent relationship
- #zone! : Zone
-
#zone=(parent : Zone)
Sets the parent relationship
Instance methods inherited from module PlaceOS::Model::Utilities::Versions
create_version(version : self) : self
create_version
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
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">
Serialize from a trusted JSON source
Serialize from a trusted YAML source
Initialize PlaceOS::Model::Settings from HTTP::Params
.
Class Method Detail
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.
Get Settings
for given parent id/s
Get Settings
for given parent id/s
Look up a settings key, if it exists and the user has the correct privilege
Query on main settings records
Gets records where the settings_id does not exist, i.e. is the main
Count of records returned by query on main settings records
Gets records where the settings_id does not exist, i.e. is the main
Query on main settings records
Gets records where the settings_id does not exist, i.e. is the main
Instance Method Detail
Base class for all Engine models
Base class for all Engine models
Base class for all Engine models
Base class for all Engine models
Decrypts settings for a user, merges into single JSON object
Assign to multiple attributes.
Assign to mulitple attributes via HTTP::Params
.
Assign to multiple attributes from a model object
Assign each field from JSON if field exists in JSON and has changed in model
Base class for all Engine models
Base class for all Engine models
Base class for all Engine models
Base class for all Engine models
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #created_at
in the set of changed attributes, whether it has changed or not.
Decrypts (if user has correct privilege) and returns the settings string
Locate the modules that will be affected by the change of this setting
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #encryption_level
in the set of changed attributes, whether it has changed or not.
Get version history
Versions are in descending order of creation
Get version history
Versions are in descending order of creation
Return the number of versions for the main record.
If the record is a version, this is always 0.
Same as #id
but may return nil
when the record hasn't been saved
instead of raising.
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #id
in the set of changed attributes, whether it has changed or not.
Base class for all Engine models
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #keys
in the set of changed attributes, whether it has changed or not.
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #modified_by_id
in the set of changed attributes, whether it has changed or not.
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #parent_id
in the set of changed attributes, whether it has changed or not.
Assign instance variable to correct type
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #parent_type
in the set of changed attributes, whether it has changed or not.
Base class for all Engine models
Base class for all Engine models
Base class for all Engine models
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #settings_id
in the set of changed attributes, whether it has changed or not.
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #settings_string
in the set of changed attributes, whether it has changed or not.
Returns a Tuple of the previous and the current value of an instance variable if it has changed
Include #updated_at
in the set of changed attributes, whether it has changed or not.