class Arca::Report

Attributes

model[R]

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

Public Class Methods

new(model) click to toggle source

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

# File lib/arca/report.rb, line 9
def initialize(model)
  @model = model
end

Public Instance Methods

calculated_permutations() click to toggle source

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.

# 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_count() click to toggle source

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

# File lib/arca/report.rb, line 47
def callbacks_count
  model.analyzed_callbacks_count
end
conditionals_count() click to toggle source

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

# File lib/arca/report.rb, line 53
def conditionals_count
  number_of_unique_conditionals(model.analyzed_callbacks_array)
end
inspect() click to toggle source

Public: Hash representation of the object for interactive consoles.

# File lib/arca/report.rb, line 17
def inspect
  to_hash.to_s
end
model_file_path() click to toggle source

Public: String file path of model.

# File lib/arca/report.rb, line 42
def model_file_path
  model.file_path
end
model_name() click to toggle source

Public: String class name of model.

# File lib/arca/report.rb, line 37
def model_name
  model.name
end
to_hash() click to toggle source

Public: Hash of compiled report data.

# 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

Private Instance Methods

number_of_unique_conditionals(analyzed_callbacks) click to toggle source

Internal: Integer representing the number of unique conditions for an Array of CallbackAnalysis objects.

analyzed_callbacks - Array of CallbackAnalysis objects.

Returns an Integer.

# File lib/arca/report.rb, line 75
def number_of_unique_conditionals(analyzed_callbacks)
  analyzed_callbacks.
    select {|analysis| analysis.conditional_symbol }.
    uniq {|analysis| analysis.conditional_target_symbol }.
    size
end