Class: Anoubis::ApplicationRecord
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Anoubis::ApplicationRecord
- Defined in:
- app/models/anoubis/application_record.rb
Overview
Main application model record class inherited from ActiveRecord::Base
Instance Attribute Summary collapse
-
#need_refresh ⇒ Boolean
Defines when table representation data should be updated even after simple update.
-
#redis ⇒ Class
Returns Redis database class.
Class Method Summary collapse
-
.redis ⇒ Class
Returns Redis database class.
-
.redis_prefix ⇒ String
Returns Redis prefix for storing cache data.
Instance Method Summary collapse
-
#after_initialize_anubis_application_record ⇒ Object
Fires after initialize default variables.
-
#can_delete(args = {}) ⇒ Boolean
Returns the ability to delete a data.
-
#can_destroy? ⇒ Boolean
Checks if this record may be destroyed.
-
#can_edit(args = {}) ⇒ Boolean
Returns the ability to edit the data.
-
#can_new(args = {}) ⇒ Boolean
Returns the ability to create new data.
-
#current_locale ⇒ String
Return defined locale according by I18n.
-
#default_locale ⇒ String
Default locale that setup in Rails.configuration.i18n.default_locale configuration parameter.
-
#get_locale ⇒ String
Returns #current_locale.
-
#get_locale_field(field, used_locale = nil) ⇒ String
Returns localized field by identifier.
-
#initialize_anubis_application_record ⇒ Object
Fires after ApplicationRecord initialized for define default values.
-
#is_field_localized(field, used_locale = nil) ⇒ Boolean
Returns true if field has localized data.
-
#redis_prefix ⇒ String
Returns Redis prefix for storing cache data.
-
#set_locale_field(field, value, used_locale = nil) ⇒ Object
Sets localized data.
-
#sys_title ⇒ String
Returns system title of table element.
Instance Attribute Details
#need_refresh ⇒ Boolean
Returns defines when table representation data should be updated even after simple update.
12 13 14 |
# File 'app/models/anoubis/application_record.rb', line 12 def need_refresh @need_refresh end |
#redis ⇒ Class
Returns Redis database class
8 9 10 |
# File 'app/models/anoubis/application_record.rb', line 8 def redis @redis end |
Class Method Details
.redis ⇒ Class
Returns Redis database class
38 39 40 |
# File 'app/models/anoubis/application_record.rb', line 38 def self.redis Redis.new end |
.redis_prefix ⇒ String
Returns Redis prefix for storing cache data. Prefix can be set in Rails.configuration.anoubis_redis_prefix configuration parameter.
57 58 59 60 61 62 63 64 |
# File 'app/models/anoubis/application_record.rb', line 57 def self.redis_prefix begin value = Rails.configuration.anoubis_redis_prefix rescue return '' end return value + ':' end |
Instance Method Details
#after_initialize_anubis_application_record ⇒ Object
Fires after initialize default variables
24 25 26 |
# File 'app/models/anoubis/application_record.rb', line 24 def after_initialize_anubis_application_record end |
#can_delete(args = {}) ⇒ Boolean
Returns the ability to delete a data. By default all items may be deleted. For another result procedure should be overridden.
183 184 185 |
# File 'app/models/anoubis/application_record.rb', line 183 def can_delete(args = {}) true end |
#can_destroy? ⇒ Boolean
Checks if this record may be destroyed.
138 139 140 141 142 143 144 145 |
# File 'app/models/anoubis/application_record.rb', line 138 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 |
#can_edit(args = {}) ⇒ Boolean
Returns the ability to edit the data. By default all items may be edited. For another result procedure should be overridden.
172 173 174 |
# File 'app/models/anoubis/application_record.rb', line 172 def can_edit(args = {}) true end |
#can_new(args = {}) ⇒ Boolean
Returns the ability to create new data. By default all items may be deleted. For another result procedure should be overridden.
161 162 163 |
# File 'app/models/anoubis/application_record.rb', line 161 def can_new(args = {}) true end |
#current_locale ⇒ String
Return defined locale according by I18n
69 70 71 |
# File 'app/models/anoubis/application_record.rb', line 69 def current_locale I18n.locale.to_s end |
#default_locale ⇒ String
Default locale that setup in Rails.configuration.i18n.default_locale configuration parameter
87 88 89 |
# File 'app/models/anoubis/application_record.rb', line 87 def default_locale Rails.configuration.i18n.default_locale.to_s end |
#get_locale ⇒ String
Returns #current_locale. If current locale isn’t set then returns #default_locale.
76 77 78 79 80 81 82 |
# File 'app/models/anoubis/application_record.rb', line 76 def get_locale if current_locale && current_locale != '' return current_locale end default_locale end |
#get_locale_field(field, used_locale = nil) ⇒ String
Returns localized field by identifier
96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/anoubis/application_record.rb', line 96 def get_locale_field(field, used_locale = nil) field = field.to_s.to_sym used_locale = 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? default_locale.to_s self[field][default_locale.to_s] end |
#initialize_anubis_application_record ⇒ Object
Fires after ApplicationRecord initialized for define default values
16 17 18 19 20 |
# File 'app/models/anoubis/application_record.rb', line 16 def initialize_anubis_application_record self.need_refresh = false after_initialize_anubis_application_record end |
#is_field_localized(field, used_locale = nil) ⇒ Boolean
Returns true if field has localized data
126 127 128 129 130 131 132 133 134 |
# File 'app/models/anoubis/application_record.rb', line 126 def is_field_localized(field, used_locale = nil) field = field.to_s.to_sym used_locale = current_locale.to_s unless used_locale return false unless self[field] return true if self[field].key? used_locale false end |
#redis_prefix ⇒ String
Returns Redis prefix for storing cache data. Prefix can be set in Rails.configuration.anoubis_redis_prefix configuration parameter.
45 46 47 48 49 50 51 52 |
# File 'app/models/anoubis/application_record.rb', line 45 def redis_prefix begin value = Rails.configuration.anoubis_redis_prefix rescue return '' end return value + ':' end |
#set_locale_field(field, value, used_locale = nil) ⇒ Object
Sets localized data
112 113 114 115 116 117 118 119 |
# File 'app/models/anoubis/application_record.rb', line 112 def set_locale_field(field, value, used_locale = nil) field = field.to_s.to_sym used_locale = current_locale.to_s unless used_locale self[field] = {} unless self[field] self[field][default_locale.to_s] = value unless self[field].key? default_locale.to_s self[field][used_locale] = value end |
#sys_title ⇒ String
Returns system title of table element
150 151 152 |
# File 'app/models/anoubis/application_record.rb', line 150 def sys_title id.to_s end |