Class: RubyDetective::JSONBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_detective/json_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJSONBuilder

Returns a new instance of JSONBuilder.



7
8
9
10
# File 'lib/ruby_detective/json_builder.rb', line 7

def initialize
  data_store = SourceRepresentation::DataStore.instance
  @classes = data_store.classes
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



5
6
7
# File 'lib/ruby_detective/json_builder.rb', line 5

def classes
  @classes
end

Class Method Details

.build(*args) ⇒ Object



12
13
14
# File 'lib/ruby_detective/json_builder.rb', line 12

def self.build(*args)
  new(*args).build
end

Instance Method Details

#buildObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_detective/json_builder.rb', line 16

def build
  classes_data_as_json = classes.map do |c|
    {
      name: c.name,
      full_name: c.path_as_text,
      namespace: c.namespace_as_text,
      lines_of_code: c.lines_of_code,
      dependencies: c.dependencies.map(&:path_as_text),
      dependents: c.dependents.map(&:path_as_text),
      file_path: c.file_path
    }
  end.to_json
end