Class: ActiveRecord::Events::Naming

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/events/naming.rb

Instance Method Summary collapse

Constructor Details

#initialize(infinitive, options = {}) ⇒ Naming

Returns a new instance of Naming.



6
7
8
9
10
11
# File 'lib/active_record/events/naming.rb', line 6

def initialize(infinitive, options = {})
  @infinitive = infinitive
  @object = options[:object].presence
  @field_name = options[:field_name].to_s
  @field_type = options[:field_type].try(:to_sym)
end

Instance Method Details

#actionObject



29
30
31
# File 'lib/active_record/events/naming.rb', line 29

def action
  concatenate(infinitive, object) + '!'
end

#collective_actionObject



37
38
39
# File 'lib/active_record/events/naming.rb', line 37

def collective_action
  concatenate(infinitive, 'all', plural_object)
end

#fieldObject



13
14
15
16
17
18
19
# File 'lib/active_record/events/naming.rb', line 13

def field
  return field_name if field_name.present?

  suffix = field_type == :date ? 'on' : 'at'

  concatenate(object, past_participle, suffix)
end

#inverse_predicateObject



25
26
27
# File 'lib/active_record/events/naming.rb', line 25

def inverse_predicate
  concatenate(object, 'not', past_participle) + '?'
end

#inverse_scopeObject



45
46
47
# File 'lib/active_record/events/naming.rb', line 45

def inverse_scope
  concatenate(object, 'not', past_participle)
end

#predicateObject



21
22
23
# File 'lib/active_record/events/naming.rb', line 21

def predicate
  concatenate(object, past_participle) + '?'
end

#safe_actionObject



33
34
35
# File 'lib/active_record/events/naming.rb', line 33

def safe_action
  concatenate(infinitive, object)
end

#scopeObject



41
42
43
# File 'lib/active_record/events/naming.rb', line 41

def scope
  concatenate(object, past_participle)
end