Sha256: b7eb0ba4a54bb001591c096124089453ad27915e62542e58c6f440ddcf2c2476

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 KB

Contents

require 'json'

module Rubrowser
  module Formatter
    class JSON
      def initialize(data)
        @data = data
      end

      def call
        {
          definitions: data.definitions.map { |d| definition_as_json(d) },
          relations: data.relations.map do |r|
            relation_as_json(r, data.definitions)
          end
        }.to_json
      end

      private

      attr_reader :data

      def definition_as_json(definition)
        {
          type: demoularize(definition.class.name),
          namespace: definition.to_s,
          circular: definition.circular?,
          file: definition.file,
          line: definition.line,
          lines: definition.lines
        }
      end

      def relation_as_json(relation, definitions)
        {
          type: demoularize(relation.class.name),
          namespace: relation.namespace.to_s,
          resolved_namespace: relation.resolve(definitions).to_s,
          caller: relation.caller_namespace.to_s,
          file: relation.file,
          circular: relation.circular?,
          line: relation.line
        }
      end

      def demoularize(class_name)
        class_name.split('::').last || ''
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubrowser-2.11 lib/rubrowser/formatter/json.rb
rubrowser-2.10 lib/rubrowser/formatter/json.rb
rubrowser-2.9.1 lib/rubrowser/formatter/json.rb
rubrowser-2.9.0 lib/rubrowser/formatter/json.rb
rubrowser-2.8.0 lib/rubrowser/formatter/json.rb
rubrowser-2.7.1 lib/rubrowser/formatter/json.rb
rubrowser-2.7.0 lib/rubrowser/formatter/json.rb
rubrowser-2.6.0 lib/rubrowser/formatter/json.rb
rubrowser-2.5.0 lib/rubrowser/formatter/json.rb
rubrowser-2.4.0 lib/rubrowser/formatter/json.rb
rubrowser-2.3.0 lib/rubrowser/formatter/json.rb
rubrowser-2.2.0 lib/rubrowser/formatter/json.rb
rubrowser-2.1.0 lib/rubrowser/formatter/json.rb
rubrowser-2.0.0 lib/rubrowser/formatter/json.rb
rubrowser-0.3.1 lib/rubrowser/formatter/json.rb
rubrowser-0.3.0 lib/rubrowser/formatter/json.rb