Class: LWS::Generic::Model
- Inherits:
-
Spyke::Base
- Object
- Spyke::Base
- LWS::Generic::Model
- Includes:
- ActiveModel::Dirty
- Defined in:
- lib/lws/apps/generic.rb
Overview
The generic model class
This model forms the base for all LWS models.
Direct Known Subclasses
Auth::Account, Auth::App, Auth::Company, Auth::Contract, Auth::Device, Auth::License, Auth::Token, Auth::UsageReport, Auth::User, CorporateWebsite::Article, CorporateWebsite::OfficeTime, CorporateWebsite::Page, CorporateWebsite::SocialPage, CorporateWebsite::SocialPost, DigitalSignage::Channel, DigitalSignage::Channel::Group, DigitalSignage::Channel::Group::Tag, DigitalSignage::Channel::Tag, DigitalSignage::Channel::TimeSchedule, DigitalSignage::Channel::TimeSchedule::Day, DigitalSignage::Channel::TimeScheduleOverride, DigitalSignage::Display, DigitalSignage::Display::Input, DigitalSignage::Display::Resolution, DigitalSignage::Layout, DigitalSignage::Layout::Category, DigitalSignage::Layout::Element, DigitalSignage::Layout::Element::Customizable, DigitalSignage::Layout::Element::Property, DigitalSignage::Layout::Version, DigitalSignage::Player, DigitalSignage::Player::Component, DigitalSignage::Player::Component::Part, DigitalSignage::Player::Configuration, DigitalSignage::Player::Configuration::Setting, DigitalSignage::Player::Log, DigitalSignage::Player::Model, DigitalSignage::Player::Model::Capability, DigitalSignage::Player::Notification, DigitalSignage::Player::Os::Branch, DigitalSignage::Player::Os::Branch::Release, DigitalSignage::Player::Os::Package, DigitalSignage::Player::Os::Package::Version, DigitalSignage::Player::Os::Package::VersionChange, DigitalSignage::Player::Os::ReleaseChannel, DigitalSignage::Player::PredefinedConfiguration, DigitalSignage::Player::PredefinedConfiguration::Setting, DigitalSignage::Player::Request, DigitalSignage::Player::Screenshot, DigitalSignage::Player::Tag, DigitalSignage::Slide, DigitalSignage::Slide::Schedule, Configuration, Maps::Map, Maps::Marker, Maps::Source, Presence::Appointment, Presence::Journal, Presence::Location, Presence::Location::Map, Presence::Location::Map::Position, Presence::Notification, Presence::Person, Presence::Reader, Resource::Collection, Resource::Collection::Item, Resource::Folder, Ticket::Attachment, Ticket::Group, Ticket::Message, Ticket::Tag, Ticket::Ticket
Instance Attribute Summary collapse
-
#created_at ⇒ String
readonly
The timestamp of when the model was created.
-
#id ⇒ Integer
readonly
The (unique) ID of the model.
-
#updated_at ⇒ String
readonly
The timestamp of when the model was last updated.
-
#url ⇒ String
readonly
The URL of the model on the REST API.
-
#url_html ⇒ String
readonly
The URL of the web/HTML page of the model.
Instance Method Summary collapse
-
#deep_dup ⇒ Model
Returns a deep copy of the model.
-
#dig(*attrs) ⇒ Object?
Extracts a nested attribute value specified by the sequence of attribute names by calling dig at each step, returning
nil
if any intermediate step isnil
. -
#reload ⇒ Hash
Reloads the attributes of this model by retrieving it from LWS via HTTP.
-
#rollback ⇒ Array<String>
Restore the attributes of this model to the previous (original) values.
-
#save ⇒ Hash, Trueclass
Saves the model to LWS via HTTP if there are any changes.
Instance Attribute Details
#created_at ⇒ String (readonly)
Returns the timestamp of when the model was created.
118 |
# File 'lib/lws/apps/generic.rb', line 118 attribute :created_at |
#id ⇒ Integer (readonly)
Returns the (unique) ID of the model.
114 |
# File 'lib/lws/apps/generic.rb', line 114 attribute :id |
#updated_at ⇒ String (readonly)
Returns the timestamp of when the model was last updated.
122 |
# File 'lib/lws/apps/generic.rb', line 122 attribute :updated_at |
#url ⇒ String (readonly)
Returns the URL of the model on the REST API.
126 |
# File 'lib/lws/apps/generic.rb', line 126 attribute :url |
#url_html ⇒ String (readonly)
Returns the URL of the web/HTML page of the model.
130 |
# File 'lib/lws/apps/generic.rb', line 130 attribute :url_html |
Instance Method Details
#deep_dup ⇒ Model
Returns a deep copy of the model.
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/lws/apps/generic.rb', line 193 def deep_dup dup_obj = super dup_obj.instance_eval do @changed_attributes = @changed_attributes.deep_dup @previously_changed = @previously_changed.deep_dup @scope = @scope.deep_dup @spyke_attributes = @spyke_attributes.deep_dup @uri_template = @uri_template.deep_dup end dup_obj end |
#dig(*attrs) ⇒ Object?
Extracts a nested attribute value specified by the sequence of attribute names by calling dig at each step, returning nil
if any intermediate step is nil
.
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/lws/apps/generic.rb', line 178 def dig(*attrs) attr = attrs.shift value = begin send(attr) rescue NoMethodError nil end return nil if value.nil? return value if attrs.empty? raise TypeError, "#{value.class} does not have #dig method" unless value.respond_to? :dig value.dig(*attrs) end |
#reload ⇒ Hash
Reloads the attributes of this model by retrieving it from LWS via HTTP.
This also clears information about tracked changes to attribute values!
151 152 153 154 155 |
# File 'lib/lws/apps/generic.rb', line 151 def reload result = super clear_changes_information if result result end |
#rollback ⇒ Array<String>
Restore the attributes of this model to the previous (original) values.
160 161 162 |
# File 'lib/lws/apps/generic.rb', line 160 def rollback restore_attributes end |
#save ⇒ Hash, Trueclass
Saves the model to LWS via HTTP if there are any changes.
168 169 170 171 172 173 |
# File 'lib/lws/apps/generic.rb', line 168 def save return true unless changed? || !persisted? result = super changes_applied if result result end |