Class: ActionLabels::ActiveModelNameExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/action_labels/active_model_name_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ ActiveModelNameExtractor

Returns a new instance of ActiveModelNameExtractor.



6
7
8
9
10
11
12
13
14
# File 'lib/action_labels/active_model_name_extractor.rb', line 6

def initialize(subject)
  subject = Array(subject).first

  if subject.nil?
    raise ArgumentError, "Cannot extract any meaningful name from NilClass"
  end

  @subject = subject
end

Instance Attribute Details

#subjectObject

Returns the value of attribute subject.



4
5
6
# File 'lib/action_labels/active_model_name_extractor.rb', line 4

def subject
  @subject
end

Instance Method Details

#extractObject



16
17
18
19
# File 'lib/action_labels/active_model_name_extractor.rb', line 16

def extract
  klass = subject.is_a?(Class) ? subject : extract_class
  klass.model_name
end