Module: ArRegion

Extended by:
ActiveSupport::Concern
Included in:
ApplicationRecord
Defined in:
lib/extensions/ar_region.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_RAILS_SEQUENCE_FACTOR =
1_000_000_000_000
COMPRESSED_ID_SEPARATOR =
'r'.freeze
CID_OR_ID_MATCHER =
"\\d+?(#{COMPRESSED_ID_SEPARATOR}\\d+)?".freeze
RE_COMPRESSED_ID =
/^(\d+)#{COMPRESSED_ID_SEPARATOR}(\d+)$/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.anonymous_class_with_ar_regionObject


15
16
17
# File 'lib/extensions/ar_region.rb', line 15

def self.anonymous_class_with_ar_region
  @klass_with_ar_region ||= Class.new(ActiveRecord::Base).send(:include, self)
end

Instance Method Details

#compressed_idObject


176
177
178
# File 'lib/extensions/ar_region.rb', line 176

def compressed_id
  self.class.compress_id(id)
end

#in_current_region?Boolean

Returns:

  • (Boolean)

159
160
161
# File 'lib/extensions/ar_region.rb', line 159

def in_current_region?
  region_number == my_region_number
end

#miq_regionObject


172
173
174
# File 'lib/extensions/ar_region.rb', line 172

def miq_region
  self.class.id_to_miq_region[region_number] || (self.class.id_to_miq_region[region_number] = MiqRegion.where(:region => region_number).first)
end

#my_region_numberObject


155
156
157
# File 'lib/extensions/ar_region.rb', line 155

def my_region_number
  self.class.my_region_number
end

#region_descriptionObject


168
169
170
# File 'lib/extensions/ar_region.rb', line 168

def region_description
  miq_region.description if miq_region
end

#region_numberObject Also known as: region_id


163
164
165
# File 'lib/extensions/ar_region.rb', line 163

def region_number
  id ? (id / self.class.rails_sequence_factor) : my_region_number
end

#split_idObject


180
181
182
# File 'lib/extensions/ar_region.rb', line 180

def split_id
  self.class.split_id(id)
end