Class: Fiveruns::Tuneup::RootStep

Inherits:
Object
  • Object
show all
Defined in:
lib/fiveruns/tuneup/step.rb

Direct Known Subclasses

Step

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.framework_layersObject



13
14
15
# File 'lib/fiveruns/tuneup/step.rb', line 13

def self.framework_layers
  [:model, :view, :controller]
end

.layersObject



9
10
11
# File 'lib/fiveruns/tuneup/step.rb', line 9

def self.layers
  framework_layers + [:other]
end

Instance Method Details

#<<(child) ⇒ Object



29
30
31
32
# File 'lib/fiveruns/tuneup/step.rb', line 29

def <<(child)
  child.depth = depth + 1
  children << child
end

#child_times_by_layerObject



60
61
62
63
64
65
66
67
# File 'lib/fiveruns/tuneup/step.rb', line 60

def child_times_by_layer
  @child_times_by_layer ||= children.inject(Hash.new(0)) do |totals, child|
    child.percentages_by_layer.each do |layer, percentage|
      totals[layer] += child.time * percentage
    end
    totals
  end
end

#childrenObject



42
43
44
# File 'lib/fiveruns/tuneup/step.rb', line 42

def children
  @children ||= []
end

#children_with_disparityObject



38
39
40
# File 'lib/fiveruns/tuneup/step.rb', line 38

def children_with_disparity
  children + [Step.disparity(disparity, self)]
end

#depthObject



25
26
27
# File 'lib/fiveruns/tuneup/step.rb', line 25

def depth
  @depth ||= 0
end

#leaf?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fiveruns/tuneup/step.rb', line 46

def leaf?
  children.blank?
end

#leavesObject



50
51
52
53
54
55
56
57
58
# File 'lib/fiveruns/tuneup/step.rb', line 50

def leaves
  @leaves ||= begin
    if children.blank?
      [self]
    else
      children.map(&:leaves).flatten
    end
  end
end

#percentages_by_layerObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fiveruns/tuneup/step.rb', line 69

def percentages_by_layer
  @percentages_by_layer ||= begin
    percentages = self.class.framework_layers.inject({}) do |map, layer|
      map[layer] = if leaf?
        self.layer == layer ? 1.0 : 0
      else
        result = child_times_by_layer[layer] / self.time
        result = nil unless result.to_s =~ /\d/
        result.is_a?(Numeric) ? result : 0 # TODO: Fix issue at source
      end
      map
    end
    fill percentages
  end
end

#schemasObject



17
18
19
# File 'lib/fiveruns/tuneup/step.rb', line 17

def schemas
  @schemas ||= {}
end

#sizeObject



34
35
36
# File 'lib/fiveruns/tuneup/step.rb', line 34

def size
  children.map(&:size).sum || 0
end

#timeObject



21
22
23
# File 'lib/fiveruns/tuneup/step.rb', line 21

def time
  children.map(&:time).sum || 0
end