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
# File 'lib/active_record/events/naming.rb', line 6

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

Instance Method Details

#actionObject



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

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

#collective_actionObject



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

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

#fieldObject



12
13
14
15
# File 'lib/active_record/events/naming.rb', line 12

def field
  suffix = field_type == :date ? 'on' : 'at'
  concatenate(object, past_participle, suffix)
end

#inverse_predicateObject



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

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

#inverse_scopeObject



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

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

#predicateObject



17
18
19
# File 'lib/active_record/events/naming.rb', line 17

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

#safe_actionObject



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

def safe_action
  concatenate(infinitive, object)
end

#scopeObject



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

def scope
  concatenate(object, past_participle)
end