Class: ModelScope::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/modelscope/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, rails_callback:, name:, defining_class:) ⇒ Callback

Returns a new instance of Callback.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/modelscope/callback.rb', line 8

def initialize(model:, rails_callback:, name:, defining_class:)
  @model = model
  @callback = rails_callback
  @name = name
  @defining_class = defining_class

  analyzer = Analyzers::CallbackAnalyzer.new(@callback, model, defining_class)

  @kind = @callback.kind
  @method_name = @callback.filter
  @conditional = analyzer.conditional?
  @origin = analyzer.origin
  @inherited = analyzer.inherited?
  @association_generated = analyzer.association_generated?
  @attribute_generated = analyzer.attribute_generated?
end

Instance Attribute Details

#association_generatedObject (readonly)

Returns the value of attribute association_generated.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def association_generated
  @association_generated
end

#attribute_generatedObject (readonly)

Returns the value of attribute attribute_generated.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def attribute_generated
  @attribute_generated
end

#conditionalObject (readonly)

Returns the value of attribute conditional.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def conditional
  @conditional
end

#inheritedObject (readonly)

Returns the value of attribute inherited.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def inherited
  @inherited
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def kind
  @kind
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def method_name
  @method_name
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def model
  @model
end

#originObject (readonly)

Returns the value of attribute origin.



5
6
7
# File 'lib/modelscope/callback.rb', line 5

def origin
  @origin
end

Instance Method Details

#callback_groupObject



25
26
27
# File 'lib/modelscope/callback.rb', line 25

def callback_group
  @name.to_s
end

#human_method_nameObject



34
35
36
# File 'lib/modelscope/callback.rb', line 34

def human_method_name
  Analyzers::ValidationAnalyzer.human_method_name(@callback.filter)
end

#validation_typeObject



29
30
31
32
# File 'lib/modelscope/callback.rb', line 29

def validation_type
  return nil unless callback_group == "validate"
  Analyzers::ValidationAnalyzer.detect_type(@callback.filter, model)
end