codetree 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,4 +26,4 @@ end.parse!
26
26
 
27
27
 
28
28
  codetree = Codetree::ParseTree.new(Dir['lib/*/*/*/*.rb'] + Dir['lib/*/*/*.rb'] + Dir['lib/*/*.rb'] + Dir['lib/*.rb'])
29
- codetree.print_tree detail: $detail, flat: $flat, quiet: $quiet
29
+ codetree.print_tree :detail => $detail, :flat => $flat, :quiet => $quiet
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Codetree::VERSION
9
9
  spec.authors = ["Romain GEORGES"]
10
10
  spec.email = ["romain@ultragreen.net"]
11
- spec.description = %q{Scan code to map methods/ classes/ modules and build tree of modules namespaces}
11
+ spec.description = %q{Scan code to map methods or classes or modules and build tree of modules namespaces}
12
12
  spec.summary = %q{Usefull tools for code audit commands}
13
13
  spec.homepage = "http://www.ultragreen.net"
14
14
  spec.license = "BSD"
@@ -19,14 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
- spec.add_dependency "ruby_parser"
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency('rspec')
26
- spec.add_development_dependency('yard')
27
- spec.add_development_dependency('rdoc')
28
- spec.add_development_dependency('roodi')
29
- spec.add_development_dependency('code_statistics')
30
- spec.add_development_dependency('yard-rspec')
22
+ spec.add_runtime_dependency 'ruby_parser', '~> 0'
23
+ spec.add_development_dependency 'rake', '~> 10.1', '>= 10.1.0'
24
+ spec.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
25
+ spec.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7.2'
26
+ spec.add_development_dependency 'rdoc', '~> 4.0', '>= 4.0.1'
27
+ spec.add_development_dependency 'roodi', '~> 3.1', '>= 3.1.1'
28
+ spec.add_development_dependency 'code_statistics', '~> 0.2', '>= 0.2.13'
29
+ spec.add_development_dependency 'yard-rspec', '~> 0.1'
30
+
31
31
 
32
32
  end
@@ -14,18 +14,24 @@ module Codetree
14
14
  attr_reader :line
15
15
  attr_reader :name
16
16
 
17
- def initialize(type: :defn, ancestors: [], scope: :none, name: "", line: 0 )
18
- @type = type
19
- @ancestors = ancestors
20
- @scope = scope
21
- @name = name
22
- @line = line
17
+ def initialize(_options = { :type => :defn, :ancestors => [], :scope => :none, :name => "", :line => 0 })
18
+ @type = _options[:type] || :defn
19
+ @ancestors = _options[:ancestors] || []
20
+ @scope = _options[:scope] || :none
21
+ @name = _options[:name] || ""
22
+ @line = _options[:line] || 0
23
23
  end
24
24
 
25
+ # @!group Virtual Scopeors
26
+
25
27
  def ancestor
26
28
  return @ancestors.last
27
29
  end
30
+
31
+ # @!endgroup
28
32
 
33
+
34
+
29
35
  def render
30
36
  return name.to_s if self.ancestors == []
31
37
  case type
@@ -36,6 +42,7 @@ module Codetree
36
42
  end
37
43
  end
38
44
 
45
+ # @!endgroup
39
46
 
40
47
  end
41
48
 
@@ -66,8 +73,9 @@ module Codetree
66
73
 
67
74
 
68
75
 
69
- def format_operator(name, detail: :full)
76
+ def format_operator(name, _options = {:detail => :full})
70
77
  res = ""
78
+ _options[:detail] ||= :full
71
79
  scope = {
72
80
  :private => { :full => "Private ", :medium => '-', :light => ''},
73
81
  :public => { :full => "Public ", :medium => "+", :light => ''},
@@ -83,14 +91,17 @@ module Codetree
83
91
  operator.ancestors.each do |ancestor|
84
92
  res += @operators[ancestor].render
85
93
  end
86
- res = scope[operator.scope][detail] + type[operator.type][detail] + res + operator.render
94
+ res = scope[operator.scope][_options[:detail]] + type[operator.type][_options[:detail]] + res + operator.render
87
95
  end
88
96
  return res
89
97
  end
90
98
 
91
99
 
92
- def print_tree(detail: :medium, flat: false, quiet: false)
93
- print_subtree(@root,0, detail: detail, flat: flat, quiet: quiet )
100
+ def print_tree(_options = { :detail => :medium, :flat => false, :quiet => false})
101
+ _options[:detail] ||= :medium
102
+ _options[:flat] ||= false
103
+ _options[:quiet] ||= false
104
+ print_subtree(@root,0, _options )
94
105
  end
95
106
 
96
107
 
@@ -116,14 +127,14 @@ module Codetree
116
127
 
117
128
 
118
129
  def register_operator(nodetype, name, linenr, ancestors)
119
- @operators[name] = Codetree::Operator::new(type: nodetype, name: name, line: linenr, ancestors: ancestors )
130
+ @operators[name] = Codetree::Operator::new({ :type => nodetype, :name => name, :line => linenr, :ancestors => ancestors })
120
131
  @operators_index[@curr_position.to_s] = [nodetype, name]
121
132
  end
122
133
 
123
134
  def define_scopes!
124
135
  @operators.each do |name,item|
125
136
  unless item.ancestor.nil? then
126
- klass = eval "#{format_operator item.ancestor, detail: :light}"
137
+ klass = eval "#{format_operator item.ancestor, :detail => :light}"
127
138
  if item.type == :defn then
128
139
  item.scope = :private if klass.private_method_defined? name
129
140
  item.scope = :protected if klass.protected_method_defined? name
@@ -157,18 +168,21 @@ module Codetree
157
168
 
158
169
 
159
170
 
160
- def print_subtree(item, level, detail: :full, flat: false, quiet: false)
171
+ def print_subtree(item, level, _options = { :detail => :full, :flat => false, :quiet => false})
172
+ _options[:flat] ||= false
173
+ _options[:detail] ||= :full
174
+ _options[:quiet] ||= false
161
175
  items = @tree[item]
162
176
  unless items == nil
163
- indent = (flat)? '': level > 0 ? sprintf("%#{level * 2}s", " ") : ""
164
- node = (quiet)? "":"* "
177
+ indent = (_options[:flat])? '': level > 0 ? sprintf("%#{level * 2}s", " ") : ""
178
+ node = (_options[:quiet])? "":"* "
165
179
  items.each do |operator|
166
- if detail == :none then
180
+ if _options[:detail] == :none then
167
181
  puts "#{indent}#{node}#{operator.name}"
168
182
  else
169
- puts "#{indent}#{node}#{format_operator operator.name, detail: detail}"
183
+ puts "#{indent}#{node}#{format_operator operator.name, :detail => _options[:detail]}"
170
184
  end
171
- print_subtree(operator, level + 1, detail: detail, flat: flat, quiet: quiet)
185
+ print_subtree(operator, level + 1, _options)
172
186
  end
173
187
  end
174
188
  end
@@ -1,3 +1,3 @@
1
1
  module Codetree
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,95 @@
1
+ require './lib/codetree.rb'
2
+
3
+
4
+ describe Codetree do
5
+
6
+ before :all do
7
+
8
+ end
9
+
10
+ subject { Codetree }
11
+ specify { subject.should be_an_instance_of Module }
12
+ context Codetree::Operator do
13
+ subject { Codetree::Operator }
14
+ specify { subject.should be_an_instance_of Class }
15
+ context "#initialize" do
16
+ it "should be possible to instanciate an Operator" do
17
+ $operator = subject.new name: :test, type: :defn, ancestors: [:Module, :Class], line: 10, scope: :public
18
+ $operator.instance_variable_get(:@name).should eq :test
19
+ $operator.instance_variable_get(:@type).should eq :defn
20
+ $operator.instance_variable_get(:@ancestors).should == [:Module, :Class]
21
+ $operator.instance_variable_get(:@line).should == 10
22
+ $operator.instance_variable_get(:@scope).should eq :public
23
+ end
24
+ end
25
+ context "Accessors" do
26
+ it "should respond to #name" do
27
+ $operator.respond_to?(:name).should be_true
28
+ $operator.name.should eq :test
29
+ end
30
+ it "should not respond to #name=" do
31
+ $operator.respond_to?(:name=).should be_false
32
+ end
33
+ it "should respond to #type" do
34
+ $operator.respond_to?(:type).should be_true
35
+ $operator.type.should eq :defn
36
+ end
37
+ it "should not respond to #type=" do
38
+ $operator.respond_to?(:type=).should be_false
39
+ end
40
+ it "should respond to #ancestors" do
41
+ $operator.respond_to?(:ancestors).should be_true
42
+ $operator.ancestors.should == [:Module, :Class]
43
+ end
44
+ it "should not respond to #ancestors=" do
45
+ $operator.respond_to?(:ancestors=).should be_false
46
+ end
47
+ it "should respond to #line" do
48
+ $operator.respond_to?(:line).should be_true
49
+ $operator.line.should == 10
50
+ end
51
+ it "should not respond to #line=" do
52
+ $operator.respond_to?(:line=).should be_false
53
+ end
54
+ it "should respond to #scope" do
55
+ $operator.respond_to?(:scope).should be_true
56
+ $operator.scope.should eq :public
57
+ end
58
+ it "should respond to #scope==" do
59
+ $operator.respond_to?(:scope=).should be_true
60
+ $operator.scope = :private
61
+ $operator.scope.should eq :private
62
+ end
63
+ end
64
+ context "#ancestor" do
65
+ it "should return the last ancestor of the instance variable @ancestors" do
66
+ $operator.ancestor.should eq :Class
67
+ end
68
+ end
69
+
70
+ context "#render" do
71
+ it "should return a correct formatted String depending of the type and if ancestors empty" do
72
+ subject.new(name: :test, type: :defn, ancestors: [], line: 10, scope: :public).render.should eq 'test'
73
+ subject.new(name: :test, type: :defs, ancestors: [], line: 10, scope: :public).render.should eq 'test'
74
+ subject.new(name: :Test, type: :class, ancestors: [], line: 10, scope: :public).render.should eq 'Test'
75
+ subject.new(name: :Test, type: :module, ancestors: [], line: 10, scope: :public).render.should eq 'Test'
76
+ subject.new(name: :Test, type: :module, ancestors: [:Module, :Class], line: 10, scope: :public).render.should eq '::Test'
77
+ subject.new(name: :Test, type: :class, ancestors: [:Module, :Class], line: 10, scope: :public).render.should eq '::Test'
78
+ subject.new(name: :test, type: :defn, ancestors: [:Module, :Class], line: 10, scope: :public).render.should eq '#test'
79
+ subject.new(name: :test, type: :defs, ancestors: [:Module, :Class], line: 10, scope: :public).render.should eq '.test'
80
+ end
81
+ end
82
+
83
+ end
84
+ context Codetree::ParseTree do
85
+ subject { Codetree::ParseTree }
86
+ specify { subject.should be_an_instance_of Class }
87
+ end
88
+ after :all do
89
+
90
+ end
91
+ end
92
+
93
+
94
+
95
+
@@ -0,0 +1 @@
1
+ require "spec_helper"
@@ -0,0 +1,16 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ end
12
+
13
+ require 'rubygems'
14
+ require 'rspec'
15
+
16
+
metadata CHANGED
@@ -1,148 +1,186 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codetree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Romain GEORGES
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: ruby_parser
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
- name: bundler
31
+ name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
33
- version: '1.3'
37
+ version: '10.1'
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 10.1.0
34
41
  type: :development
35
42
  prerelease: false
36
43
  version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
37
45
  requirements:
38
46
  - - ~>
39
47
  - !ruby/object:Gem::Version
40
- version: '1.3'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
48
+ version: '10.1'
49
+ - - ! '>='
46
50
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
51
+ version: 10.1.0
55
52
  - !ruby/object:Gem::Dependency
56
53
  name: rspec
57
54
  requirement: !ruby/object:Gem::Requirement
55
+ none: false
58
56
  requirements:
59
- - - '>='
57
+ - - ~>
60
58
  - !ruby/object:Gem::Version
61
- version: '0'
59
+ version: '2.14'
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 2.14.1
62
63
  type: :development
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
66
+ none: false
65
67
  requirements:
66
- - - '>='
68
+ - - ~>
67
69
  - !ruby/object:Gem::Version
68
- version: '0'
70
+ version: '2.14'
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: 2.14.1
69
74
  - !ruby/object:Gem::Dependency
70
75
  name: yard
71
76
  requirement: !ruby/object:Gem::Requirement
77
+ none: false
72
78
  requirements:
73
- - - '>='
79
+ - - ~>
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: '0.8'
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: 0.8.7.2
76
85
  type: :development
77
86
  prerelease: false
78
87
  version_requirements: !ruby/object:Gem::Requirement
88
+ none: false
79
89
  requirements:
80
- - - '>='
90
+ - - ~>
81
91
  - !ruby/object:Gem::Version
82
- version: '0'
92
+ version: '0.8'
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: 0.8.7.2
83
96
  - !ruby/object:Gem::Dependency
84
97
  name: rdoc
85
98
  requirement: !ruby/object:Gem::Requirement
99
+ none: false
86
100
  requirements:
87
- - - '>='
101
+ - - ~>
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '4.0'
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: 4.0.1
90
107
  type: :development
91
108
  prerelease: false
92
109
  version_requirements: !ruby/object:Gem::Requirement
110
+ none: false
93
111
  requirements:
94
- - - '>='
112
+ - - ~>
95
113
  - !ruby/object:Gem::Version
96
- version: '0'
114
+ version: '4.0'
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 4.0.1
97
118
  - !ruby/object:Gem::Dependency
98
119
  name: roodi
99
120
  requirement: !ruby/object:Gem::Requirement
121
+ none: false
100
122
  requirements:
101
- - - '>='
123
+ - - ~>
102
124
  - !ruby/object:Gem::Version
103
- version: '0'
125
+ version: '3.1'
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: 3.1.1
104
129
  type: :development
105
130
  prerelease: false
106
131
  version_requirements: !ruby/object:Gem::Requirement
132
+ none: false
107
133
  requirements:
108
- - - '>='
134
+ - - ~>
109
135
  - !ruby/object:Gem::Version
110
- version: '0'
136
+ version: '3.1'
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: 3.1.1
111
140
  - !ruby/object:Gem::Dependency
112
141
  name: code_statistics
113
142
  requirement: !ruby/object:Gem::Requirement
143
+ none: false
114
144
  requirements:
115
- - - '>='
145
+ - - ~>
116
146
  - !ruby/object:Gem::Version
117
- version: '0'
147
+ version: '0.2'
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: 0.2.13
118
151
  type: :development
119
152
  prerelease: false
120
153
  version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
121
155
  requirements:
122
- - - '>='
156
+ - - ~>
123
157
  - !ruby/object:Gem::Version
124
- version: '0'
158
+ version: '0.2'
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: 0.2.13
125
162
  - !ruby/object:Gem::Dependency
126
163
  name: yard-rspec
127
164
  requirement: !ruby/object:Gem::Requirement
165
+ none: false
128
166
  requirements:
129
- - - '>='
167
+ - - ~>
130
168
  - !ruby/object:Gem::Version
131
- version: '0'
169
+ version: '0.1'
132
170
  type: :development
133
171
  prerelease: false
134
172
  version_requirements: !ruby/object:Gem::Requirement
173
+ none: false
135
174
  requirements:
136
- - - '>='
175
+ - - ~>
137
176
  - !ruby/object:Gem::Version
138
- version: '0'
139
- description: Scan code to map methods/ classes/ modules and build tree of modules
177
+ version: '0.1'
178
+ description: Scan code to map methods or classes or modules and build tree of modules
140
179
  namespaces
141
180
  email:
142
181
  - romain@ultragreen.net
143
182
  executables:
144
183
  - codetree
145
- - '#codetree#'
146
184
  extensions: []
147
185
  extra_rdoc_files: []
148
186
  files:
@@ -155,30 +193,37 @@ files:
155
193
  - codetree.gemspec
156
194
  - lib/codetree.rb
157
195
  - lib/codetree/version.rb
196
+ - spec/codetree_spec.rb
197
+ - spec/init_spec.rb
198
+ - spec/spec_helper.rb
158
199
  - ultragreen_roodi_coding_convention.yml
159
- - bin/#codetree#
160
200
  homepage: http://www.ultragreen.net
161
201
  licenses:
162
202
  - BSD
163
- metadata: {}
164
203
  post_install_message:
165
204
  rdoc_options: []
166
205
  require_paths:
167
206
  - lib
168
207
  required_ruby_version: !ruby/object:Gem::Requirement
208
+ none: false
169
209
  requirements:
170
- - - '>='
210
+ - - ! '>='
171
211
  - !ruby/object:Gem::Version
172
212
  version: '0'
173
213
  required_rubygems_version: !ruby/object:Gem::Requirement
214
+ none: false
174
215
  requirements:
175
- - - '>='
216
+ - - ! '>='
176
217
  - !ruby/object:Gem::Version
177
218
  version: '0'
178
219
  requirements: []
179
220
  rubyforge_project:
180
- rubygems_version: 2.0.7
221
+ rubygems_version: 1.8.29
181
222
  signing_key:
182
- specification_version: 4
223
+ specification_version: 3
183
224
  summary: Usefull tools for code audit commands
184
- test_files: []
225
+ test_files:
226
+ - spec/codetree_spec.rb
227
+ - spec/init_spec.rb
228
+ - spec/spec_helper.rb
229
+ has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 4d91d00d736664c8259bcf21a68fc5e50393bdfb
4
- data.tar.gz: 9ad1aff5a42d9061015a8cf6fa952df6a804e6ef
5
- SHA512:
6
- metadata.gz: 52ac70fe88fbb3e7cf6ba3eb10c02ab0f9d27c018201980dc28c598d6e27e8831108f7e259a5af4292e80e510409686725f4b68f92db2130332cb4cd2ca21d6f
7
- data.tar.gz: a6fc3bd8b44e2eb0e591862be65c4398945e73f833f4ba8c5224a3133933bfd6fc85cef7cb50cd5d0a6ff7c72908fcff420feba5144482de0eac7427df6f7f7e
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'codetree'
3
- require 'optparse'
4
-
5
- OptionParser.new do |opts|
6
- opts.banner = "Usage: codetree [options]"
7
-
8
- opts.on("-f", "--[no-]flat", "display flat list/tree") do |v|
9
- $flat = v || false
10
- end
11
- opts.on("-d", "--detail", "Specify a detail value [:none,:light,:medium,:full]") do |v|
12
- $detail = v || :medium
13
- end
14
-
15
- end.parse!
16
-
17
-
18
- p $detail
19
- p $flat
20
-
21
-
22
- codetree = Codetree::ParseTree.new(Dir['lib/*/*/*/*.rb'] + Dir['lib/*/*/*.rb'] + Dir['lib/*/*.rb'] + Dir['lib/*.rb'])
23
- codetree.print_tree detail: $detail, flat: $flat