Class: Anoubis::Core::ApplicationRecord
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Anoubis::Core::ApplicationRecord
- Defined in:
- app/models/anoubis/core/application_record.rb
Overview
Default ApplicationRecord for Anoubis::Core library.
Direct Known Subclasses
Sso::Client::ApplicationRecord, Sso::Server::System, Sso::Server::User, Tenant::ApplicationRecord, Tenant::Group, Tenant::GroupLocale, Tenant::GroupMenu, Tenant::MenuLocale, Tenant::System, Tenant::SystemLocale, Tenant::SystemMenu, Tenant::Tenant
Instance Attribute Summary collapse
-
#can_delete(args = {}) ⇒ Boolean
readonly
Returns the ability to delete a data.
-
#can_edit(args = {}) ⇒ Boolean
readonly
Returns the ability to edit the data.
-
#can_new(args = {}) ⇒ Boolean
readonly
Returns the ability to create new data.
-
#created_at ⇒ DateTime
The date and time when item had been created.
-
#current_user ⇒ String
Definition of current user for this record.
-
#need_refresh ⇒ Boolean
Defines when table representation data should be updated even after simple update.
-
#redis ⇒ Object
Pointer to Redis database.
-
#sys_title ⇒ String
readonly
Returns model’s system title.
-
#updated_at ⇒ DateTime
The date and time when item had been updated.
Block of UUID functions collapse
-
#new_uuid ⇒ String
Generates new UUID data.
Block of Redis functions collapse
-
.redis ⇒ Object
Returns reference to Redis database.
-
.redis_prefix ⇒ Object
Returns defined application prefix for redis cache for model.
-
#redis_prefix ⇒ Object
Returns defined application prefix for redis cache for current record.
Class Method Summary collapse
-
.get_where(object, pid = 0) ⇒ Hash
Returns the default ActiveRecord ‘where’ for defined model.
Instance Method Summary collapse
-
#after_initialize_core_anubis_model ⇒ Object
Is called after initialization Anoubis::Core ActiveRecord.
-
#can_destroy? ⇒ Boolean
Checks if this record may be destroyed.
-
#current_locale ⇒ Object
Return defined locale according by I18n.
-
#current_locale=(value) ⇒ Object
Sets current locale and nullifies locale variable that presents model translation data.
- #default_locale ⇒ Object
- #get_locale ⇒ Object
- #get_locale_field(field, used_locale = nil) ⇒ Object
- #is_field_localized(field, used_locale = nil) ⇒ Object
- #set_locale_field(field, value, used_locale = nil) ⇒ Object
Instance Attribute Details
#can_delete(args = {}) ⇒ Boolean (readonly)
Returns the ability to delete a data. By default all items may be deleted. For another result procedure should be overridden.
34 35 36 |
# File 'app/models/anoubis/core/application_record.rb', line 34 def can_delete @can_delete end |
#can_edit(args = {}) ⇒ Boolean (readonly)
Returns the ability to edit the data. By default all items may be edited. For another result procedure should be overridden.
31 32 33 |
# File 'app/models/anoubis/core/application_record.rb', line 31 def can_edit @can_edit end |
#can_new(args = {}) ⇒ Boolean (readonly)
Returns the ability to create new data. By default all items may be deleted. For another result procedure should be overridden.
28 29 30 |
# File 'app/models/anoubis/core/application_record.rb', line 28 def can_new @can_new end |
#created_at ⇒ DateTime
Returns the date and time when item had been created.
|
# File 'app/models/anoubis/core/application_record.rb', line 6
|
#current_user ⇒ String
Returns definition of current user for this record.
18 19 20 |
# File 'app/models/anoubis/core/application_record.rb', line 18 def current_user @current_user end |
#need_refresh ⇒ Boolean
Returns defines when table representation data should be updated even after simple update.
22 |
# File 'app/models/anoubis/core/application_record.rb', line 22 class_attribute :need_refresh, default: false |
#redis ⇒ Object
Returns pointer to Redis database.
14 |
# File 'app/models/anoubis/core/application_record.rb', line 14 class_attribute :redis |
#sys_title ⇒ String (readonly)
Returns model’s system title. Default value is the row ID. For another result procedure should be overridden.
25 26 27 |
# File 'app/models/anoubis/core/application_record.rb', line 25 def sys_title @sys_title end |
#updated_at ⇒ DateTime
Returns the date and time when item had been updated.
|
# File 'app/models/anoubis/core/application_record.rb', line 9
|
Class Method Details
.get_where(object, pid = 0) ⇒ Hash
Returns the default ActiveRecord ‘where’ for defined model.
71 72 73 |
# File 'app/models/anoubis/core/application_record.rb', line 71 def self.get_where(object, pid = 0) { } end |
.redis ⇒ Object
Returns reference to Redis database
203 204 205 |
# File 'app/models/anoubis/core/application_record.rb', line 203 def self.redis Redis.new end |
.redis_prefix ⇒ Object
Returns defined application prefix for redis cache for model. Default value ”
192 193 194 195 196 197 198 199 |
# File 'app/models/anoubis/core/application_record.rb', line 192 def self.redis_prefix begin value = Rails.configuration.redis_prefix rescue return '' end return value + ':' end |
Instance Method Details
#after_initialize_core_anubis_model ⇒ Object
Is called after initialization Anoubis::Core ActiveRecord. Sets default parameters.
43 44 45 46 47 |
# File 'app/models/anoubis/core/application_record.rb', line 43 def after_initialize_core_anubis_model self.need_refresh = false self.redis = Redis.new self.current_user = nil end |
#can_destroy? ⇒ Boolean
Checks if this record may be destroyed.
57 58 59 60 61 62 63 64 |
# File 'app/models/anoubis/core/application_record.rb', line 57 def can_destroy? result = true self.class.reflect_on_all_associations.all? do |assoc| result = self.send(assoc.name).nil? if assoc.macro == :has_one result = self.send(assoc.name).empty? if (assoc.macro == :has_many) && result end result end |
#current_locale ⇒ Object
Return defined locale according by I18n
51 52 53 |
# File 'app/models/anoubis/core/application_record.rb', line 51 def current_locale I18n.locale.to_s end |
#current_locale=(value) ⇒ Object
Sets current locale and nullifies locale variable that presents model translation data.
109 110 111 112 |
# File 'app/models/anoubis/core/application_record.rb', line 109 def current_locale=(value) @current_locale = value @model_locale = nil end |
#default_locale ⇒ Object
217 218 219 |
# File 'app/models/anoubis/core/application_record.rb', line 217 def default_locale Rails.configuration.i18n.default_locale.to_s end |
#get_locale ⇒ Object
209 210 211 212 213 214 215 |
# File 'app/models/anoubis/core/application_record.rb', line 209 def get_locale if self.current_locale && self.current_locale != '' return self.current_locale end self.default_locale end |
#get_locale_field(field, used_locale = nil) ⇒ Object
221 222 223 224 225 226 227 228 229 230 |
# File 'app/models/anoubis/core/application_record.rb', line 221 def get_locale_field(field, used_locale = nil) field = field.to_s.to_sym used_locale = self.current_locale.to_s unless used_locale return '' unless self[field] return self[field][used_locale] if self[field].key? used_locale return '' unless self[field].key? self.default_locale.to_s self[field][self.default_locale.to_s] end |
#is_field_localized(field, used_locale = nil) ⇒ Object
241 242 243 244 245 246 247 248 249 |
# File 'app/models/anoubis/core/application_record.rb', line 241 def is_field_localized(field, used_locale = nil) field = field.to_s.to_sym used_locale = self.current_locale.to_s unless used_locale return false unless self[field] return true if self[field].key? used_locale false end |
#new_uuid ⇒ String
Generates new UUID data
170 171 172 |
# File 'app/models/anoubis/core/application_record.rb', line 170 def new_uuid SecureRandom.uuid end |
#redis_prefix ⇒ Object
Returns defined application prefix for redis cache for current record. Default value ”
181 182 183 184 185 186 187 188 |
# File 'app/models/anoubis/core/application_record.rb', line 181 def redis_prefix begin value = Rails.configuration.redis_prefix rescue return '' end return value + ':' end |
#set_locale_field(field, value, used_locale = nil) ⇒ Object
232 233 234 235 236 237 238 239 |
# File 'app/models/anoubis/core/application_record.rb', line 232 def set_locale_field(field, value, used_locale = nil) field = field.to_s.to_sym used_locale = self.current_locale.to_s unless used_locale self[field] = {} unless self[field] self[field][self.default_locale.to_s] = value unless self[field].key? self.default_locale.to_s self[field][used_locale] = value end |