society 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/bin/society +3 -0
- data/lib/society.rb +13 -0
- data/lib/society/analyzer.rb +134 -0
- data/lib/society/cli.rb +26 -0
- data/lib/society/matrix.rb +36 -0
- data/lib/society/node.rb +19 -0
- data/lib/society/object_graph.rb +13 -0
- data/lib/society/parser.rb +52 -0
- data/lib/society/version.rb +3 -0
- data/society.gemspec +33 -0
- data/spec/analyzer_spec.rb +36 -0
- data/spec/fixtures/bar.rb +6 -0
- data/spec/fixtures/foo.rb +22 -0
- data/spec/matrix_spec.rb +27 -0
- data/spec/node_spec.rb +30 -0
- data/spec/spec_helper.rb +7 -0
- metadata +217 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 0f4ebba200840ada80d8b3179a38dbc15d14ad22
         | 
| 4 | 
            +
              data.tar.gz: fbb95e9ef6fd48d8f5856362aeaa9d38118160d6
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 30410ae520e57a09d9e789a3e0d69da885be214e24cf4cc3c5067b4ce381971fc09396140421fb360199b67ad45d48d3165a73318444c3c002d861be0f9c0fdc
         | 
| 7 | 
            +
              data.tar.gz: b11f888a578119d654ad89122f25c694af6c12c8729084f4641944769fef7e72e00c849eb5dcf017a13c8c83ebd17db466c5753c986fa5c1767986d2f2315af9
         | 
    
        data/.gitignore
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            *.gem
         | 
| 2 | 
            +
            *.rbc
         | 
| 3 | 
            +
            .bundle
         | 
| 4 | 
            +
            .config
         | 
| 5 | 
            +
            .yardoc
         | 
| 6 | 
            +
            Gemfile.lock
         | 
| 7 | 
            +
            InstalledFiles
         | 
| 8 | 
            +
            _yardoc
         | 
| 9 | 
            +
            coverage
         | 
| 10 | 
            +
            doc/
         | 
| 11 | 
            +
            lib/bundler/man
         | 
| 12 | 
            +
            pkg
         | 
| 13 | 
            +
            rdoc
         | 
| 14 | 
            +
            spec/reports
         | 
| 15 | 
            +
            test/tmp
         | 
| 16 | 
            +
            test/version_tmp
         | 
| 17 | 
            +
            tmp
         | 
| 18 | 
            +
            *.bundle
         | 
| 19 | 
            +
            *.so
         | 
| 20 | 
            +
            *.o
         | 
| 21 | 
            +
            *.a
         | 
| 22 | 
            +
            mkmf.log
         | 
| 23 | 
            +
            .console_history
         | 
    
        data/.rspec
    ADDED
    
    
    
        data/CODE_OF_CONDUCT.md
    ADDED
    
    | @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # CODE OF CONDUCT
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            This project has adopted version 0.4 of the [Contributor Covenant](https://github.com/bantik/contributor_covenant/).
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            If any participant in this project has issues or takes exception with a contribution, they are obligated to provide constructive feedback and never resort to personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            We promise to extend courtesy and respect to everyone involved in this project regardless of gender, gender identity, sexual orientation, ability or disability, ethnicity, religion, or level of experience.
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2014 Coraline Ada Ehmke  / Instructure.inc
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            # Society
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Society analyzes and presents a social graph of relationships between classes or methods.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem 'society'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            And then execute:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                $ bundle
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Or install it yourself as:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ gem install society
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Initialize a parser with source files:
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                 parser = Society::Parser.new("path/to/models")
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            Generate an object dependency graph:
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                 graph = parser.class_graph
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            Generate a method dependency graph:
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                 graph = parser.method_graph
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            Generate JSON dependency matrix for export to d3:
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                parser.matrix.to_jsno
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ## TODO
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            * Add fukuzatsu as a dependency
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            * Wrap fukuzatsu parsing and remove duplicate classes
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            ## Contributing
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            Please note that this project is released with a [Contributor Code of Conduct](https://github.com/Bantik/society/blob/master/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
         | 
| 46 | 
            +
             | 
| 47 | 
            +
             | 
| 48 | 
            +
            1. Fork it ( https://github.com/[my-github-username]/society/fork )
         | 
| 49 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 50 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 51 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 52 | 
            +
            5. Create a new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/society
    ADDED
    
    
    
        data/lib/society.rb
    ADDED
    
    | @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require "fileutils"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Society
         | 
| 4 | 
            +
            end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require_relative "society/analyzer"
         | 
| 7 | 
            +
            require_relative "society/cli"
         | 
| 8 | 
            +
            require_relative "society/matrix"
         | 
| 9 | 
            +
            require_relative "society/node"
         | 
| 10 | 
            +
            require_relative "society/object_graph"
         | 
| 11 | 
            +
            require_relative "society/parser"
         | 
| 12 | 
            +
            require_relative "society/version"
         | 
| 13 | 
            +
             | 
| @@ -0,0 +1,134 @@ | |
| 1 | 
            +
            require 'parser/current'
         | 
| 2 | 
            +
            require 'pry'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Society
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              class Analyzer
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                attr_reader :content
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                DEFAULT_CLASS_NAME = "Unknown"
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def initialize(content)
         | 
| 13 | 
            +
                  @content = content
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def class_name
         | 
| 17 | 
            +
                  find_class(parsed) || DEFAULT_CLASS_NAME
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def methods
         | 
| 21 | 
            +
                  @methods ||= methods_from(parsed)
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def constants
         | 
| 25 | 
            +
                  @constants ||= constants_from(parsed)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                private
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def method_list
         | 
| 31 | 
            +
                  @method_list ||= method_names_from(parsed.children.first)
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def method_names_from(node, found=[])
         | 
| 35 | 
            +
                  if node.type == :def || node.type == :defs
         | 
| 36 | 
            +
                    name = node.loc.name
         | 
| 37 | 
            +
                    found << content[name.begin_pos..name.end_pos - 1].to_sym
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                  node.children.each do |child|
         | 
| 40 | 
            +
                    method_names_from(child, found) if parent_node?(child)
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                  found
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                def constants_from(node, found=[])
         | 
| 46 | 
            +
                  if node.type == :const
         | 
| 47 | 
            +
                    expression = node.loc.expression
         | 
| 48 | 
            +
                    found << content[expression.begin_pos..expression.end_pos - 1]
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                  node.children.each do |child|
         | 
| 51 | 
            +
                    constants_from(child, found) if parent_node?(child)
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
                  found.reject{ |constant| constant == class_name }
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                def find_class(node)
         | 
| 57 | 
            +
                  return unless node && node.respond_to?(:type)
         | 
| 58 | 
            +
                  concat = []
         | 
| 59 | 
            +
                  if node.type == :module || node.type == :class
         | 
| 60 | 
            +
                    concat << text_at(node.loc.name.begin_pos, node.loc.name.end_pos)
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
                  concat << node.children.map{|child| find_class(child)}.compact
         | 
| 63 | 
            +
                  concat.flatten.reject(&:empty?).join('::')
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def extract_references_from(node, found=[])
         | 
| 67 | 
            +
                  return found unless node && node.respond_to?(:type)
         | 
| 68 | 
            +
                  if node.type == :send
         | 
| 69 | 
            +
                    reference = node.loc.expression
         | 
| 70 | 
            +
                    found << node.children.last
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
                  node.children.each do |child|
         | 
| 73 | 
            +
                    extract_references_from(child, found)
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
                  found.select{|name| method_list.include?(name)}
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                def methods_from(node, found=[])
         | 
| 79 | 
            +
                  if node.type == :def || node.type == :defs
         | 
| 80 | 
            +
                    name = node.loc.name
         | 
| 81 | 
            +
                    expression = node.loc.expression
         | 
| 82 | 
            +
                    type = case(node.type)
         | 
| 83 | 
            +
                      when :defs
         | 
| 84 | 
            +
                        :class
         | 
| 85 | 
            +
                      when :def
         | 
| 86 | 
            +
                        :instance
         | 
| 87 | 
            +
                      when :class
         | 
| 88 | 
            +
                        :none
         | 
| 89 | 
            +
                    end
         | 
| 90 | 
            +
                    found << ParsedMethod.new(
         | 
| 91 | 
            +
                      name: content[name.begin_pos..name.end_pos - 1],
         | 
| 92 | 
            +
                      content: content[expression.begin_pos..expression.end_pos - 1],
         | 
| 93 | 
            +
                      type: type,
         | 
| 94 | 
            +
                      refs: extract_references_from(node)
         | 
| 95 | 
            +
                    )
         | 
| 96 | 
            +
                  end
         | 
| 97 | 
            +
                  node.children.each do |child|
         | 
| 98 | 
            +
                    if parent_node?(child)
         | 
| 99 | 
            +
                      methods_from(child, found)
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
                  found
         | 
| 103 | 
            +
                end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                def parent_node?(node)
         | 
| 106 | 
            +
                  node.respond_to?(:type) || node.respond_to?(:children)
         | 
| 107 | 
            +
                end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                def parse!
         | 
| 110 | 
            +
                  traverse(parsed) && complexity
         | 
| 111 | 
            +
                end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                def parsed
         | 
| 114 | 
            +
                  @parsed ||= ::Parser::CurrentRuby.parse(content)
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                def text_at(start_pos, end_pos)
         | 
| 118 | 
            +
                  content[start_pos..end_pos - 1]
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                def traverse(node, accumulator=[], extract_methods=false)
         | 
| 122 | 
            +
                  accumulator << node.type
         | 
| 123 | 
            +
                  node.children.each do |child|
         | 
| 124 | 
            +
                    if parent_node?(child)
         | 
| 125 | 
            +
                      accumulator << child.type
         | 
| 126 | 
            +
                      traverse(child, accumulator)
         | 
| 127 | 
            +
                    end
         | 
| 128 | 
            +
                  end
         | 
| 129 | 
            +
                  accumulator
         | 
| 130 | 
            +
                end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
              end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
            end
         | 
    
        data/lib/society/cli.rb
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            require "thor"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Society
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              class CLI < Thor
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                desc_text = ""
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                desc "from PATH_TO_FILE", desc_text
         | 
| 10 | 
            +
                def from(path="./")
         | 
| 11 | 
            +
                  parser = Society::Parser.new(path)
         | 
| 12 | 
            +
                  parser.parse_files
         | 
| 13 | 
            +
                  parser.report
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                default_task :from
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                private
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def formatter
         | 
| 21 | 
            +
                  Formatters::Text
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Society
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              class Matrix
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_reader :nodes
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(nodes)
         | 
| 10 | 
            +
                  @nodes = nodes
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def to_json
         | 
| 14 | 
            +
                  { names: node_names, matrix: matrix }.to_json
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                private
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def node_names
         | 
| 20 | 
            +
                  self.nodes.map(&:name)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def matrix
         | 
| 24 | 
            +
                  reference_matrix = [[]]
         | 
| 25 | 
            +
                  nodes.each_with_index do |node, i|
         | 
| 26 | 
            +
                    references = node_names.map do |name|
         | 
| 27 | 
            +
                      node.references.include?(name) ? 1 : 0
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
                    reference_matrix.push(references)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                  reference_matrix
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            end
         | 
    
        data/lib/society/node.rb
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module Society
         | 
| 2 | 
            +
              class Node
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_reader   :name       # method or class name
         | 
| 5 | 
            +
                attr_reader   :address    # file name or file name + loc
         | 
| 6 | 
            +
                attr_accessor :edges      # relation between nodes
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize(name: name, address: address, edges: edges=[])
         | 
| 9 | 
            +
                  @name = name
         | 
| 10 | 
            +
                  @address = address
         | 
| 11 | 
            +
                  @edges = edges
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def edge_count
         | 
| 15 | 
            +
                  edges.count
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            require 'fukuzatsu'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Society
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              class Parser < Fukuzatsu::Parser
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_reader :parsed_files
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(start_path)
         | 
| 10 | 
            +
                  super(start_path, :none, 0)
         | 
| 11 | 
            +
                  @parsed_files = parse_files
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def class_graph
         | 
| 15 | 
            +
                  @class_graph ||= begin
         | 
| 16 | 
            +
                    graph = ObjectGraph.new
         | 
| 17 | 
            +
                    graph.nodes = parsed_files.map do |parsed_file|
         | 
| 18 | 
            +
                      Node.new(
         | 
| 19 | 
            +
                        name: parsed_file.class_name,
         | 
| 20 | 
            +
                        address: parsed_file.path_to_file,
         | 
| 21 | 
            +
                        edges: parsed_file.class_references
         | 
| 22 | 
            +
                      )
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                    graph
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def method_graph
         | 
| 29 | 
            +
                  @method_graph ||= begin
         | 
| 30 | 
            +
                    graph = ObjectGraph.new
         | 
| 31 | 
            +
                    target = parsed_files.first
         | 
| 32 | 
            +
                    graph.nodes = target.methods.map do |method|
         | 
| 33 | 
            +
                      Node.new(
         | 
| 34 | 
            +
                        name: method.name,
         | 
| 35 | 
            +
                        address: target.class_name,
         | 
| 36 | 
            +
                        edges: method.references
         | 
| 37 | 
            +
                      )
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                    graph
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def matrix(graph)
         | 
| 44 | 
            +
                  Society::Matrix.new(graph.nodes)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def reset_output_directory
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            end
         | 
    
        data/society.gemspec
    ADDED
    
    | @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'society/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "society"
         | 
| 8 | 
            +
              spec.version       = Society::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Coraline Ada Ehmke", "Kerri Miller"]
         | 
| 10 | 
            +
              spec.email         = ["coraline@instructure.com", "kerrizor@gmail.com"]
         | 
| 11 | 
            +
              spec.summary       = %q{Social graph for Ruby objects}
         | 
| 12 | 
            +
              spec.description   = %q{Social graph for Ruby objects}
         | 
| 13 | 
            +
              spec.homepage      = ""
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files -z`.split("\x0")
         | 
| 17 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_dependency "fukuzatsu", ">= 1.0.5"
         | 
| 22 | 
            +
              spec.add_dependency "parser"
         | 
| 23 | 
            +
              spec.add_dependency "rainbow"
         | 
| 24 | 
            +
              spec.add_dependency "terminal-table"
         | 
| 25 | 
            +
              spec.add_dependency "thor"
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              spec.add_development_dependency "bundler", "~> 1.6"
         | 
| 28 | 
            +
              spec.add_development_dependency "pry"
         | 
| 29 | 
            +
              spec.add_development_dependency "rake"
         | 
| 30 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 31 | 
            +
              spec.add_development_dependency "simplecov"
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            end
         | 
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Society::Analyzer do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              let(:source) { File.open("./spec/fixtures/foo.rb", "r").read }
         | 
| 6 | 
            +
              let(:analyzer) { Society::Analyzer.new(source) }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              describe "#initialize" do
         | 
| 9 | 
            +
                it "assigns its content" do
         | 
| 10 | 
            +
                  expect(analyzer.content).to eq(source)
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              describe "#class_name" do
         | 
| 15 | 
            +
                xit "doesn't get confused by multiple class declarations in one file"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                it "returns a class name" do
         | 
| 18 | 
            +
                  expect(analyzer.class_name).to eq "Foo"
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              describe "#methods" do
         | 
| 23 | 
            +
                it "returns a list of methods from its source" do
         | 
| 24 | 
            +
                  expected = ["#penultimate_method", "#initial_method", "#external_call", "#ultimate_method"]
         | 
| 25 | 
            +
                  expect(analyzer.methods.map(&:name)).to eq(expected)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              describe "constants" do
         | 
| 30 | 
            +
                it "returns a list of classes" do
         | 
| 31 | 
            +
                  expected = ["Bar"]
         | 
| 32 | 
            +
                  expect(analyzer.constants).to eq(expected)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            end
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            class Foo
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              def penultimate_method
         | 
| 4 | 
            +
                ultimate_method
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def initial_method
         | 
| 8 | 
            +
                penultimate_method
         | 
| 9 | 
            +
                penultimate_method
         | 
| 10 | 
            +
                penultimate_method
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def external_call
         | 
| 14 | 
            +
                Bar.new.say_hello
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              private
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def ultimate_method
         | 
| 20 | 
            +
                self.to_s
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
    
        data/spec/matrix_spec.rb
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Society::Matrix do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              let(:node)   { Struct.new(:name, :references)}
         | 
| 6 | 
            +
              let(:nodes)  {
         | 
| 7 | 
            +
                [
         | 
| 8 | 
            +
                  node.new("foo", %w{bar bat baz}),
         | 
| 9 | 
            +
                  node.new("bar", %w{foo bat baz})
         | 
| 10 | 
            +
                ]
         | 
| 11 | 
            +
              }
         | 
| 12 | 
            +
              let(:matrix) { Society::Matrix.new(nodes) }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              describe "#initialize" do
         | 
| 15 | 
            +
                it "assigns its nodes" do
         | 
| 16 | 
            +
                  expect(matrix.nodes).to eq(nodes)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              describe "#to_json" do
         | 
| 21 | 
            +
                it "generates a json representation" do
         | 
| 22 | 
            +
                  expected = "{\"names\":[\"foo\",\"bar\"],\"matrix\":[[],[0,1],[1,0]]}"
         | 
| 23 | 
            +
                  expect(matrix.to_json).to eq(expected)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            end
         | 
    
        data/spec/node_spec.rb
    ADDED
    
    | @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Society::Node do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              let(:node) { Society::Node.new(
         | 
| 6 | 
            +
                  name:     "Foo",
         | 
| 7 | 
            +
                  address:  "./foo.rb",
         | 
| 8 | 
            +
                  edges:    %w{Bar Bat}
         | 
| 9 | 
            +
                )
         | 
| 10 | 
            +
              }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              describe "#initialize" do
         | 
| 13 | 
            +
                it "assigns its name" do
         | 
| 14 | 
            +
                  expect(node.name).to eq("Foo")
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
                it "assigns its address" do
         | 
| 17 | 
            +
                  expect(node.address).to eq("./foo.rb")
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
                it "assigns its edges" do
         | 
| 20 | 
            +
                  expect(node.edges).to eq(["Bar", "Bat"])
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              describe "#edge_count" do
         | 
| 25 | 
            +
                it "returns a count of its edges" do
         | 
| 26 | 
            +
                  expect(node.edge_count).to eq 2
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,217 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: society
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.13.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Coraline Ada Ehmke
         | 
| 8 | 
            +
            - Kerri Miller
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2014-10-22 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: fukuzatsu
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                requirements:
         | 
| 18 | 
            +
                - - ">="
         | 
| 19 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 20 | 
            +
                    version: 1.0.5
         | 
| 21 | 
            +
              type: :runtime
         | 
| 22 | 
            +
              prerelease: false
         | 
| 23 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 24 | 
            +
                requirements:
         | 
| 25 | 
            +
                - - ">="
         | 
| 26 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 27 | 
            +
                    version: 1.0.5
         | 
| 28 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 29 | 
            +
              name: parser
         | 
| 30 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 31 | 
            +
                requirements:
         | 
| 32 | 
            +
                - - ">="
         | 
| 33 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 34 | 
            +
                    version: '0'
         | 
| 35 | 
            +
              type: :runtime
         | 
| 36 | 
            +
              prerelease: false
         | 
| 37 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 38 | 
            +
                requirements:
         | 
| 39 | 
            +
                - - ">="
         | 
| 40 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 41 | 
            +
                    version: '0'
         | 
| 42 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 43 | 
            +
              name: rainbow
         | 
| 44 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 45 | 
            +
                requirements:
         | 
| 46 | 
            +
                - - ">="
         | 
| 47 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 48 | 
            +
                    version: '0'
         | 
| 49 | 
            +
              type: :runtime
         | 
| 50 | 
            +
              prerelease: false
         | 
| 51 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 52 | 
            +
                requirements:
         | 
| 53 | 
            +
                - - ">="
         | 
| 54 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 55 | 
            +
                    version: '0'
         | 
| 56 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 57 | 
            +
              name: terminal-table
         | 
| 58 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 59 | 
            +
                requirements:
         | 
| 60 | 
            +
                - - ">="
         | 
| 61 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 62 | 
            +
                    version: '0'
         | 
| 63 | 
            +
              type: :runtime
         | 
| 64 | 
            +
              prerelease: false
         | 
| 65 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 66 | 
            +
                requirements:
         | 
| 67 | 
            +
                - - ">="
         | 
| 68 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                    version: '0'
         | 
| 70 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 71 | 
            +
              name: thor
         | 
| 72 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 73 | 
            +
                requirements:
         | 
| 74 | 
            +
                - - ">="
         | 
| 75 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 76 | 
            +
                    version: '0'
         | 
| 77 | 
            +
              type: :runtime
         | 
| 78 | 
            +
              prerelease: false
         | 
| 79 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 80 | 
            +
                requirements:
         | 
| 81 | 
            +
                - - ">="
         | 
| 82 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 83 | 
            +
                    version: '0'
         | 
| 84 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 85 | 
            +
              name: bundler
         | 
| 86 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 87 | 
            +
                requirements:
         | 
| 88 | 
            +
                - - "~>"
         | 
| 89 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 90 | 
            +
                    version: '1.6'
         | 
| 91 | 
            +
              type: :development
         | 
| 92 | 
            +
              prerelease: false
         | 
| 93 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 94 | 
            +
                requirements:
         | 
| 95 | 
            +
                - - "~>"
         | 
| 96 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 97 | 
            +
                    version: '1.6'
         | 
| 98 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 99 | 
            +
              name: pry
         | 
| 100 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 101 | 
            +
                requirements:
         | 
| 102 | 
            +
                - - ">="
         | 
| 103 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 104 | 
            +
                    version: '0'
         | 
| 105 | 
            +
              type: :development
         | 
| 106 | 
            +
              prerelease: false
         | 
| 107 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 108 | 
            +
                requirements:
         | 
| 109 | 
            +
                - - ">="
         | 
| 110 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 111 | 
            +
                    version: '0'
         | 
| 112 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 113 | 
            +
              name: rake
         | 
| 114 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 115 | 
            +
                requirements:
         | 
| 116 | 
            +
                - - ">="
         | 
| 117 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 118 | 
            +
                    version: '0'
         | 
| 119 | 
            +
              type: :development
         | 
| 120 | 
            +
              prerelease: false
         | 
| 121 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 122 | 
            +
                requirements:
         | 
| 123 | 
            +
                - - ">="
         | 
| 124 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 125 | 
            +
                    version: '0'
         | 
| 126 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 127 | 
            +
              name: rspec
         | 
| 128 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 129 | 
            +
                requirements:
         | 
| 130 | 
            +
                - - ">="
         | 
| 131 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 132 | 
            +
                    version: '0'
         | 
| 133 | 
            +
              type: :development
         | 
| 134 | 
            +
              prerelease: false
         | 
| 135 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 136 | 
            +
                requirements:
         | 
| 137 | 
            +
                - - ">="
         | 
| 138 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 139 | 
            +
                    version: '0'
         | 
| 140 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 141 | 
            +
              name: simplecov
         | 
| 142 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 143 | 
            +
                requirements:
         | 
| 144 | 
            +
                - - ">="
         | 
| 145 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 146 | 
            +
                    version: '0'
         | 
| 147 | 
            +
              type: :development
         | 
| 148 | 
            +
              prerelease: false
         | 
| 149 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 150 | 
            +
                requirements:
         | 
| 151 | 
            +
                - - ">="
         | 
| 152 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 153 | 
            +
                    version: '0'
         | 
| 154 | 
            +
            description: Social graph for Ruby objects
         | 
| 155 | 
            +
            email:
         | 
| 156 | 
            +
            - coraline@instructure.com
         | 
| 157 | 
            +
            - kerrizor@gmail.com
         | 
| 158 | 
            +
            executables:
         | 
| 159 | 
            +
            - society
         | 
| 160 | 
            +
            extensions: []
         | 
| 161 | 
            +
            extra_rdoc_files: []
         | 
| 162 | 
            +
            files:
         | 
| 163 | 
            +
            - ".gitignore"
         | 
| 164 | 
            +
            - ".rspec"
         | 
| 165 | 
            +
            - CODE_OF_CONDUCT.md
         | 
| 166 | 
            +
            - Gemfile
         | 
| 167 | 
            +
            - LICENSE.txt
         | 
| 168 | 
            +
            - README.md
         | 
| 169 | 
            +
            - Rakefile
         | 
| 170 | 
            +
            - bin/society
         | 
| 171 | 
            +
            - lib/society.rb
         | 
| 172 | 
            +
            - lib/society/analyzer.rb
         | 
| 173 | 
            +
            - lib/society/cli.rb
         | 
| 174 | 
            +
            - lib/society/matrix.rb
         | 
| 175 | 
            +
            - lib/society/node.rb
         | 
| 176 | 
            +
            - lib/society/object_graph.rb
         | 
| 177 | 
            +
            - lib/society/parser.rb
         | 
| 178 | 
            +
            - lib/society/version.rb
         | 
| 179 | 
            +
            - society.gemspec
         | 
| 180 | 
            +
            - spec/analyzer_spec.rb
         | 
| 181 | 
            +
            - spec/fixtures/bar.rb
         | 
| 182 | 
            +
            - spec/fixtures/foo.rb
         | 
| 183 | 
            +
            - spec/matrix_spec.rb
         | 
| 184 | 
            +
            - spec/node_spec.rb
         | 
| 185 | 
            +
            - spec/spec_helper.rb
         | 
| 186 | 
            +
            homepage: ''
         | 
| 187 | 
            +
            licenses:
         | 
| 188 | 
            +
            - MIT
         | 
| 189 | 
            +
            metadata: {}
         | 
| 190 | 
            +
            post_install_message: 
         | 
| 191 | 
            +
            rdoc_options: []
         | 
| 192 | 
            +
            require_paths:
         | 
| 193 | 
            +
            - lib
         | 
| 194 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 195 | 
            +
              requirements:
         | 
| 196 | 
            +
              - - ">="
         | 
| 197 | 
            +
                - !ruby/object:Gem::Version
         | 
| 198 | 
            +
                  version: '0'
         | 
| 199 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 200 | 
            +
              requirements:
         | 
| 201 | 
            +
              - - ">="
         | 
| 202 | 
            +
                - !ruby/object:Gem::Version
         | 
| 203 | 
            +
                  version: '0'
         | 
| 204 | 
            +
            requirements: []
         | 
| 205 | 
            +
            rubyforge_project: 
         | 
| 206 | 
            +
            rubygems_version: 2.2.2
         | 
| 207 | 
            +
            signing_key: 
         | 
| 208 | 
            +
            specification_version: 4
         | 
| 209 | 
            +
            summary: Social graph for Ruby objects
         | 
| 210 | 
            +
            test_files:
         | 
| 211 | 
            +
            - spec/analyzer_spec.rb
         | 
| 212 | 
            +
            - spec/fixtures/bar.rb
         | 
| 213 | 
            +
            - spec/fixtures/foo.rb
         | 
| 214 | 
            +
            - spec/matrix_spec.rb
         | 
| 215 | 
            +
            - spec/node_spec.rb
         | 
| 216 | 
            +
            - spec/spec_helper.rb
         | 
| 217 | 
            +
            has_rdoc: 
         |