analyst 0.15.0 → 0.16.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b73349858dc8cc8e23a7bcee486149fa81fa14b
4
- data.tar.gz: e8d736fd3c97802f6a8bf7db970ae730385938e0
3
+ metadata.gz: 25e03d345e3eee79249da960a221c1635de9ded7
4
+ data.tar.gz: 939e2a44f33bc42afed68a253be53e4110c0ea21
5
5
  SHA512:
6
- metadata.gz: 121c7e0d71706490dd637a48d718002a217b4fa2c190708ed9cd8c8d2fef02758cb118f0704afbd3fa397922571f09fa9270ee2dd53eb5b68266678309d9b0cb
7
- data.tar.gz: 6306167886e6d7f9e4d1b6ff3bff588525805d18a6aec93b03f0c85164def809851bcfa0c54e617002813a52f43ab5a354f9e8da3f8300dadd7c71ff00539d0f
6
+ metadata.gz: 385373476be049c30d9ebccb8ab096496587eae69a85678e420631cf7c1bfb9ce04336b3a316b78e36f0f293186c8967714e3d7fe6d77857e776dfcd60daaa07
7
+ data.tar.gz: 8423b501882aab60fac8dfea3b59272d539718731ac6a40e42152c0a512f339a68e8985c31717ecd6d3354d934fb3bd2eb9f4cd710ad53c794a99c91da7cff92
@@ -1,12 +1,8 @@
1
- #TODO add == to association
2
- # TODO look thru the singleton_methods for ones on (self),
3
- # and also look for the ones from 'class << self' constructs, which will be
4
- # found in (sclass) nodes (which will be some sort of Entity)
5
-
6
1
  module Analyst
7
-
8
2
  module Entities
9
- class Class < Analyst::Entities::Module
3
+ class Class < Entity
4
+
5
+ include HasMethods
10
6
 
11
7
  handles_node :class
12
8
 
@@ -16,33 +12,27 @@ module Analyst
16
12
  "Class"
17
13
  end
18
14
 
19
- def imethods
20
- @imethods ||= contents.select { |entity| entity.is_a? Analyst::Entities::InstanceMethod }
21
- end
22
-
23
- def cmethods
24
- some_methods = smethods.select { |method| method.target.type == :self }
25
- other_methods = singleton_class_blocks { |block| block.target.type == :self }.map(&:smethods).flatten
26
- some_methods + other_methods
15
+ def singleton_class_blocks
16
+ contents.select { |entity| entity.is_a? Analyst::Entities::SingletonClass }
27
17
  end
28
18
 
29
- def all_methods
30
- cmethods + imethods
19
+ def name
20
+ name_entity.name
31
21
  end
32
22
 
33
- def singleton_class_blocks
34
- contents.select { |entity| entity.is_a? Analyst::Entities::SingletonClass }
23
+ def full_name
24
+ parent.full_name.empty? ? name : parent.full_name + '::' + name
35
25
  end
36
26
 
37
27
  private
38
28
 
39
- def smethods
40
- @smethods ||= contents.select do |entity|
41
- entity.is_a? Analyst::Entities::SingletonMethod
42
- end
29
+ def name_entity
30
+ @name_entity ||= process_node(name_node)
43
31
  end
44
32
 
33
+ def name_node
34
+ ast.children.first
35
+ end
45
36
  end
46
-
47
37
  end
48
38
  end
@@ -0,0 +1,28 @@
1
+ module Analyst
2
+
3
+ module Entities
4
+ class ConstantAssignment < Entity
5
+
6
+ handles_node :casgn
7
+
8
+ def name
9
+ name_node.to_s
10
+ end
11
+
12
+ def full_name
13
+ scope.nil? ? name : scope.full_name + '::' + name
14
+ end
15
+
16
+ def scope
17
+ @scope ||= process_node(ast.children.first)
18
+ end
19
+
20
+ private
21
+
22
+ def name_node
23
+ ast.children[1]
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -35,6 +35,14 @@ module Analyst
35
35
  @constants ||= top_level_constants + contents.map(&:constants).flatten
36
36
  end
37
37
 
38
+ def constant_assignments
39
+ @constant_assignments ||= top_level_constant_assignments + contents.map(&:constant_assignments).flatten
40
+ end
41
+
42
+ def top_level_constant_assignments
43
+ @top_level_constant_assignments ||= contents_of_type(Entities::ConstantAssignment)
44
+ end
45
+
38
46
  def top_level_constants
39
47
  @top_level_constants ||= contents_of_type(Entities::Constant)
40
48
  end
@@ -14,6 +14,10 @@ module Analyst
14
14
  parent.source_data_for(self)
15
15
  end
16
16
 
17
+ def location
18
+ file_path
19
+ end
20
+
17
21
  def origin_source
18
22
  ::File.open(file_path, 'r').read
19
23
  end
@@ -0,0 +1,34 @@
1
+ module Analyst
2
+
3
+ module Entities
4
+
5
+ module HasMethods
6
+
7
+ def imethods
8
+ @imethods ||= contents.select { |entity| entity.is_a? Analyst::Entities::InstanceMethod }
9
+ end
10
+
11
+ def cmethods
12
+ some_methods = smethods.select { |method| method.target.type == :self }
13
+ other_methods = singleton_class_blocks { |block| block.target.type == :self }.map(&:smethods).flatten
14
+ some_methods + other_methods
15
+ end
16
+
17
+ def all_methods
18
+ cmethods + imethods
19
+ end
20
+
21
+ def singleton_class_blocks
22
+ contents.select { |entity| entity.is_a? Analyst::Entities::SingletonClass }
23
+ end
24
+
25
+ private
26
+
27
+ def smethods
28
+ @smethods ||= contents.select do |entity|
29
+ entity.is_a? Analyst::Entities::SingletonMethod
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,8 @@ module Analyst
2
2
  module Entities
3
3
  class Module < Entity
4
4
 
5
+ include HasMethods
6
+
5
7
  handles_node :module
6
8
 
7
9
  def kind
@@ -27,15 +27,19 @@ module Analyst
27
27
  throw "Entity tree malformed - Source or File hsould have caught this call"
28
28
  end
29
29
 
30
- private
31
-
32
- attr_reader :source_data
30
+ def inspect
31
+ "\#<#{self.class}>"
32
+ end
33
33
 
34
34
  def contents
35
35
  # skip all top-level entities, cuz they're all Files and Sources
36
36
  @contents ||= actual_contents.map(&:contents).flatten
37
37
  end
38
38
 
39
+ private
40
+
41
+ attr_reader :source_data
42
+
39
43
  def actual_contents
40
44
  @actual_contents ||= ast.children.map { |child| process_node(child) }
41
45
  end
@@ -11,7 +11,11 @@ module Analyst
11
11
  end
12
12
 
13
13
  def file_path
14
- "$PARSED FROM SOURCE$"
14
+ "$SOURCE$"
15
+ end
16
+
17
+ def location
18
+ file_path
15
19
  end
16
20
 
17
21
  def origin_source
@@ -9,12 +9,14 @@ module Analyst
9
9
  def_delegators :root, :classes, :top_level_classes, :constants,
10
10
  :methods
11
11
 
12
- def self.for_files(path_to_files)
13
- file_paths = if File.directory?(path_to_files)
14
- Dir.glob(File.join(path_to_files, "**", "*.rb"))
15
- else
16
- [path_to_files]
17
- end
12
+ def self.for_files(*path_to_files)
13
+ file_paths = path_to_files.map do |path|
14
+ if File.directory?(path)
15
+ Dir.glob(File.join(path, "**", "*.rb"))
16
+ else
17
+ path
18
+ end
19
+ end.flatten
18
20
 
19
21
  wrapped_asts = file_paths.map do |path|
20
22
  ast = ::Parser::CurrentRuby.parse(File.open(path, 'r').read)
@@ -1,3 +1,3 @@
1
1
  module Analyst
2
- VERSION = "0.15.0"
2
+ VERSION = "0.16.1"
3
3
  end
data/lib/analyst.rb CHANGED
@@ -5,6 +5,7 @@ require 'parser/current'
5
5
  require_relative "analyst/parser"
6
6
  require_relative "analyst/processor"
7
7
  require_relative "analyst/version"
8
+ require_relative "analyst/entities/mixins/has_methods"
8
9
  require_relative "analyst/entities/entity"
9
10
  require_relative "analyst/entities/root"
10
11
  require_relative "analyst/entities/file"
@@ -14,6 +15,7 @@ require_relative "analyst/entities/module"
14
15
  require_relative "analyst/entities/class"
15
16
  require_relative "analyst/entities/interpolated_string"
16
17
  require_relative "analyst/entities/constant"
18
+ require_relative "analyst/entities/constant_assignment"
17
19
  require_relative "analyst/entities/conditional"
18
20
  require_relative "analyst/entities/method"
19
21
  require_relative "analyst/entities/method_call"
@@ -28,8 +30,8 @@ module Analyst
28
30
 
29
31
  module ClassMethods
30
32
 
31
- def for_files(path_to_files)
32
- Analyst::Parser.for_files(path_to_files)
33
+ def for_files(*path_to_files)
34
+ Analyst::Parser.for_files(*path_to_files)
33
35
  end
34
36
 
35
37
  alias :for_file :for_files
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analyst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coraline Ada Ehmke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-06 00:00:00.000000000 Z
12
+ date: 2014-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
@@ -216,12 +216,14 @@ files:
216
216
  - lib/analyst/entities/code_block.rb
217
217
  - lib/analyst/entities/conditional.rb
218
218
  - lib/analyst/entities/constant.rb
219
+ - lib/analyst/entities/constant_assignment.rb
219
220
  - lib/analyst/entities/entity.rb
220
221
  - lib/analyst/entities/file.rb
221
222
  - lib/analyst/entities/hash.rb
222
223
  - lib/analyst/entities/interpolated_string.rb
223
224
  - lib/analyst/entities/method.rb
224
225
  - lib/analyst/entities/method_call.rb
226
+ - lib/analyst/entities/mixins/has_methods.rb
225
227
  - lib/analyst/entities/module.rb
226
228
  - lib/analyst/entities/pair.rb
227
229
  - lib/analyst/entities/root.rb