Class: RubyLens::ShowcaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/rubylens/showcase_model.rb

Constant Summary collapse

SIGNAL_FIELDS =
ArtModelBuilder::SIGNAL_FIELDS
TOTAL_FIELDS =
%w[namespaces packages dependencyStars renderedDependencyStars].freeze
CATEGORY_FIELDS =
%w[core tests].freeze
ANNOTATION_LIMIT =
200
ANNOTATION_CATEGORIES =
%w[core dependencies tests].freeze
OMITTED_ANNOTATION_NAMES =
%w[BasicObject Kernel Object].freeze
RUBY_NAME_PATTERN =
/\A\p{Lu}[\p{L}\p{N}_]*(?:::\p{Lu}[\p{L}\p{N}_]*)*\z/
MAX_ANNOTATION_NAME_LENGTH =
160
RSPEC_PROXY_PREFIX =
"RSpec example group #"
LEGACY_MORPHOLOGY_ROW =
[MorphologyClassifier::SPIRAL, *MorphologyClassifier::DEFAULT_KNOBS].freeze

Instance Method Summary collapse

Constructor Details

#initialize(model, details: false) ⇒ ShowcaseModel

Returns a new instance of ShowcaseModel.



19
20
21
22
# File 'lib/rubylens/showcase_model.rb', line 19

def initialize(model, details: false)
  @model = model
  @details = details == true
end

Instance Method Details

#callObject

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubylens/showcase_model.rb', line 24

def call
  packages = @model.fetch("packages")
  package_morphologies = @model.fetch("packageMorphologies")
  raise Error, "package morphology rows must align with packages" unless package_morphologies.length == packages.length

  showcase = {
    "schema" => "rubylens.showcase.v4",
    "projectName" => @model.fetch("projectName"),
    "details" => @details,
    "domains" => project_hash(@model.fetch("domains"), SIGNAL_FIELDS),
    "morphology" => morphology_row,
    "namespaces" => @model.fetch("namespaces").map { |row| numeric_row(row, 15) },
    "packages" => packages.map { |row| numeric_row(row, 9) },
    "packageMorphologies" => package_morphologies.map { |row| numeric_row(row, 10) },
    "dependencySystems" => @model.fetch("dependencySystems", []).map { |row| numeric_row(row, 2) },
    "dependencyStars" => @model.fetch("dependencyStars").map { |row| numeric_row(row, 8) },
  }
  return showcase unless @details

  showcase.merge(
    "totals" => project_hash(@model.fetch("totals"), TOTAL_FIELDS),
    "categoryStats" => CATEGORY_FIELDS.to_h do |category|
      [category, numeric_row(@model.fetch("categoryStats").fetch(category), 4)]
    end,
    "pinnedNamespaceAnchors" => pinned_namespace_anchors,
    "annotations" => annotation_projection,
  )
end