Class: Arca::Report

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/arca/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Report

Arca::Report takes an Arca::Model and compiles the analyzed callback data into a short overview report for the model.



9
10
11
# File 'lib/arca/report.rb', line 9

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Public: Arca::Model representing the ActiveRecord class being reported.



14
15
16
# File 'lib/arca/report.rb', line 14

def model
  @model
end

Instance Method Details

#calculated_permutationsObject

Public: Integer representing the possible number of permutations stemming from conditionals for an instance of the model being reported during the lifecycle of the object.



63
64
65
66
67
# File 'lib/arca/report.rb', line 63

def calculated_permutations
  permutations = model.analyzed_callbacks.inject([]) do |results, (key, analyzed_callbacks)|
    results << 2 ** number_of_unique_conditionals(analyzed_callbacks)
  end.sum - number_of_unique_conditionals(model.analyzed_callbacks_array)
end

#callbacks_countObject

Public: Integer representing the number of callbacks used in this model.



47
48
49
# File 'lib/arca/report.rb', line 47

def callbacks_count
  model.analyzed_callbacks_count
end

#conditionals_countObject

Public: Integer representing the number of conditionals used in callback for the model being reported.



53
54
55
# File 'lib/arca/report.rb', line 53

def conditionals_count
  number_of_unique_conditionals(model.analyzed_callbacks_array)
end

#inspectObject

Public: Hash representation of the object for interactive consoles.



17
18
19
# File 'lib/arca/report.rb', line 17

def inspect
  to_hash.to_s
end

#model_file_pathObject

Public: String file path of model.



42
43
44
# File 'lib/arca/report.rb', line 42

def model_file_path
  model.file_path
end

#model_nameObject

Public: String class name of model.



37
38
39
# File 'lib/arca/report.rb', line 37

def model_name
  model.name
end

#to_hashObject

Public: Hash of compiled report data.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/arca/report.rb', line 22

def to_hash
  {
    :model_name                  => model_name,
    :model_file_path             => Arca.relative_path(model_file_path),
    :callbacks_count             => callbacks_count,
    :conditionals_count          => conditionals_count,
    :lines_between_count         => lines_between_count,
    :external_callbacks_count    => external_callbacks_count,
    :external_targets_count      => external_targets_count,
    :external_conditionals_count => external_conditionals_count,
    :calculated_permutations     => calculated_permutations
  }
end