Module: ActiveRecord::SimpleIndexName

Defined in:
lib/active_record/simple_index_name.rb,
lib/active_record/simple_index_name/railtie.rb,
lib/active_record/simple_index_name/version.rb,
lib/active_record/simple_index_name/configuration.rb,
lib/active_record/simple_index_name/enable_shorten.rb,
lib/active_record/simple_index_name/disable_shorten.rb,
lib/active_record/simple_index_name/active_record_ext_7_0.rb,
lib/active_record/simple_index_name/active_record_ext_7_1.rb

Defined Under Namespace

Modules: ActiveRecordExt_7_0, ActiveRecordExt_7_1, DisableShorten, EnableShorten Classes: Configuration, Railtie

Constant Summary collapse

VERSION =
"1.1.1"

Class Method Summary collapse

Class Method Details

.configObject



9
10
11
# File 'lib/active_record/simple_index_name.rb', line 9

def self.config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



13
14
15
# File 'lib/active_record/simple_index_name.rb', line 13

def self.configure
  yield config if block_given?
end

.current_shorten?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
# File 'lib/active_record/simple_index_name.rb', line 25

def self.current_shorten?
  case Thread.current[:simple_index_name_shorten_mode]
  when :enable
    true
  when :disable
    false
  else
    config.auto_shorten
  end
end

.with_shorten(shorten) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/active_record/simple_index_name.rb', line 17

def self.with_shorten(shorten)
  Thread.current[:simple_index_name_shorten_mode] = shorten

  yield if block_given?
ensure
  Thread.current[:simple_index_name_shorten_mode] = nil
end