object_tree 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,27 +1,79 @@
1
1
  # ObjectTree
2
2
 
3
3
  Rubyのオブジェクト関係をtreeっぽく表示
4
+ 1.8の対応はまだ出来ていません。
4
5
 
5
6
  ## Installation
6
7
 
8
+ Or install it yourself as:
9
+
10
+ $ gem install object_tree
11
+
7
12
  Add this line to your application's Gemfile:
8
13
 
9
14
  gem 'object_tree'
10
15
 
11
- And then execute:
16
+ ## Usage
12
17
 
13
- $ bundle
18
+ ``` ruby
19
+ require 'object_tree'
14
20
 
15
- Or install it yourself as:
21
+ class A
22
+ end
16
23
 
17
- $ gem install object_tree
24
+ class B < A
25
+ end
18
26
 
19
- ## Usage
27
+ class C < A
28
+ end
29
+
30
+ tree = ObjectTree::Tree.create(A)
31
+ tree.draw
32
+ ```
33
+
34
+ ```zsh
35
+ <C>A
36
+ ├─ ─ ── <C>C
37
+ └─ ─ ── <C>B
38
+ ```
20
39
 
21
- Object以下のクラス関係を表示
40
+ こんな感じでtreeっぽく出力してくれる。
22
41
 
23
- tree = ObjectTree::Tree.create(Object)
42
+
43
+ ```ruby
44
+ require 'object_tree'
45
+
46
+ module D
47
+ end
48
+
49
+ module E
50
+ end
51
+
52
+ class A
53
+ include D
54
+ end
55
+
56
+ class B < A
57
+ end
58
+
59
+ class C < A
60
+ include E
61
+ end
62
+
63
+ tree = ObjectTree::Tree.create(A, true)
24
64
  tree.draw
65
+ ```
66
+
67
+ ```zsh
68
+ <M>D
69
+ └─ ─ ── <C>A
70
+ ├─ ─ ── <M>E
71
+ │ └─ ─ ── <C>C
72
+ └─ ─ ── <C>B
73
+ ```
74
+
75
+ 第二引数をtrueにするとmoduleも表示してくれる。
76
+
25
77
 
26
78
  ## Contributing
27
79
 
data/example/sample.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'object_tree'
2
- require 'active_record'
3
2
 
4
3
  module D
5
4
  end
@@ -7,33 +6,16 @@ end
7
6
  module E
8
7
  end
9
8
 
10
- module F
11
- end
12
-
13
- module G
14
- end
15
-
16
- class A
17
- prepend F
18
- end
19
-
20
- class H
9
+ class A
10
+ include D
21
11
  end
22
12
 
23
13
  class B < A
24
- include D
25
- include E
26
- prepend G
27
14
  end
28
15
 
29
16
  class C < A
30
17
  include E
31
- include D
32
18
  end
33
19
 
34
-
35
- tree = ObjectTree::Tree.create(A)
36
- tree.draw
37
-
38
20
  tree = ObjectTree::Tree.create(A, true)
39
21
  tree.draw
data/example/test.rb ADDED
@@ -0,0 +1,5 @@
1
+ a = ObjectSpace.each_object(Class).to_a
2
+ require 'rails'
3
+ b = ObjectSpace.each_object(Class).to_a
4
+
5
+ puts (b - a)
@@ -1,3 +1,3 @@
1
1
  module ObjectTree
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/object_tree.gemspec CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ObjectTree::VERSION
9
9
  spec.authors = ["siman-man"]
10
10
  spec.email = ["k128585@ie.u-ryukyu.ac.jp"]
11
- spec.description = "this is object tree"
12
- spec.summary = "hoge piyo"
13
- spec.homepage = ""
11
+ spec.description = "this is ruby object tree show like tree commnad!"
12
+ spec.summary = "tree command like show object hierarchy"
13
+ spec.homepage = "https://github.com/siman-man/object_tree"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - siman-man
@@ -13,6 +14,7 @@ dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
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
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,11 +38,12 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
- description: this is object tree
46
+ description: this is ruby object tree show like tree commnad!
42
47
  email:
43
48
  - k128585@ie.u-ryukyu.ac.jp
44
49
  executables: []
@@ -51,33 +56,33 @@ files:
51
56
  - README.md
52
57
  - Rakefile
53
58
  - example/sample.rb
54
- - example/sample.rb~
59
+ - example/test.rb
55
60
  - lib/object_tree.rb
56
- - lib/object_tree.rb~
57
61
  - lib/object_tree/version.rb
58
62
  - object_tree.gemspec
59
- homepage: ''
63
+ homepage: https://github.com/siman-man/object_tree
60
64
  licenses:
61
65
  - MIT
62
- metadata: {}
63
66
  post_install_message:
64
67
  rdoc_options: []
65
68
  require_paths:
66
69
  - lib
67
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
68
72
  requirements:
69
73
  - - ! '>='
70
74
  - !ruby/object:Gem::Version
71
75
  version: '0'
72
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
73
78
  requirements:
74
79
  - - ! '>='
75
80
  - !ruby/object:Gem::Version
76
81
  version: '0'
77
82
  requirements: []
78
83
  rubyforge_project:
79
- rubygems_version: 2.0.3
84
+ rubygems_version: 1.8.23
80
85
  signing_key:
81
- specification_version: 4
82
- summary: hoge piyo
86
+ specification_version: 3
87
+ summary: tree command like show object hierarchy
83
88
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGM0NTg2ZTdmMTRlYzBjNjdkYjc1ZDcxOGM0MDUwM2JhOGZiZTYwNg==
5
- data.tar.gz: !binary |-
6
- YjQwYWEyYWI0MzFkODFmMjE3OGY0Mzk3NDRmZjZiOGFmOWY0MDczMQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OGFhNjI4YWI2Mjk0MDdlNWMwNmQwYWE1NjYxNzg0ZjMxMTgwMjJlMGMxYWM3
10
- YjE3YWNlZmYzYzU5MjQwOGNhZmU3YzAzOTI1MzgxYmFmZDUzY2ZmOTMzMWU1
11
- MDUzNDA3MmNiZDRjZWI3MDQzMDZlYWQxMzZjMGI4NzA2ODg1NjE=
12
- data.tar.gz: !binary |-
13
- M2RlNTEzZjY3NDhkZGU5MTFlNGQxNjlmOGUyNWM3MWY1ZTY5YWE2MjhjZjlj
14
- MWRiODRmYTI0MjRhM2ZkNTcyOGM5NDNhZDA5MzE1OGY3ZDg5N2U2MjlhOWEy
15
- Mjg1MDk4ODRmMGRkOTZlMTVhZGMxZDlmYTliYTQ2N2VjNDk4NDk=
data/example/sample.rb~ DELETED
@@ -1,39 +0,0 @@
1
- require 'object_tree'
2
- require 'active_record'
3
-
4
- module D
5
- end
6
-
7
- module E
8
- end
9
-
10
- module F
11
- end
12
-
13
- module G
14
- end
15
-
16
- class A
17
- prepend F
18
- end
19
-
20
- class H
21
- end
22
-
23
- class B < A
24
- include D
25
- include E
26
- prepend G
27
- end
28
-
29
- class C < A
30
- include E
31
- include D
32
- end
33
-
34
-
35
- tree = ObjectTree::Tree.create(BasicObject)
36
- tree.draw
37
-
38
- tree = ObjectTree::Tree.create(BasicObject, true)
39
- tree.draw
data/lib/object_tree.rb~ DELETED
@@ -1,145 +0,0 @@
1
- # encoding: utf-8
2
- require "object_tree/version"
3
-
4
- class Module
5
- def prepended_modules
6
- ancestors = self.ancestors
7
- ancestors[0..ancestors.find_index(self)] - [self]
8
- end
9
- end
10
-
11
- module ObjectTree
12
- class Tree
13
- attr_reader :tree
14
- SPACE_SIZE = 6
15
-
16
- # 31: red, 32: green, 33: yellow, 34: blue, 35: pink, 36: aqua, 37: gray
17
- MCOLOR = 31
18
- CCOLOR = 32
19
-
20
- def initialize(klass, mflag = false)
21
- @tree = Hash.new{|h, k| h[k] = [] }
22
- @mflag = mflag
23
- @root_class = klass
24
-
25
- if klass == BasicObject
26
- klass = Object
27
- @tree[BasicObject] << Object
28
- end
29
-
30
- create_object_tree(object_list(klass))
31
- end
32
-
33
- class << self
34
- alias :create :new
35
- end
36
-
37
- def singleton(klass)
38
- class << klass; self end
39
- end
40
-
41
- def object_list(klass)
42
- ObjectSpace.each_object(singleton(klass)) do |subclass|
43
- if klass != subclass
44
- @tree[klass] << subclass
45
- object_list(subclass) unless @tree.has_key?(subclass)
46
- end
47
- end
48
-
49
- @tree
50
- end
51
-
52
- def create_object_tree(tree)
53
- tree.each do |klass1, subclasses1|
54
- tree.each do |klass2, subclasses2|
55
- if klass1 > klass2
56
- tree[klass1] -= (subclasses2 - [klass2])
57
- end
58
- end
59
- end
60
-
61
- tree
62
- end
63
-
64
- def draw
65
- if @tree.size.zero?
66
- puts "\e[#{CCOLOR}m<C>\e[m#{@root_class}"
67
- else
68
- @last_check = []
69
- draw_tree({ @root_class => @tree.first.last }, 0)
70
- end
71
- end
72
-
73
- def draw_tree(tree, nest, root = true, last = false)
74
-
75
- @last_check[nest-1] = last if nest > 0
76
-
77
- tree.each do |klass, subclasses|
78
- if ( @mflag && klass.kind_of?(Class) && !klass.superclass.nil? )
79
- module_list = klass.ancestors[0..klass.ancestors.find_index(klass.superclass)-1].reverse - [klass, klass.superclass] - klass.prepended_modules
80
-
81
- module_list.each_with_index do |m, add|
82
- puts "\e[#{MCOLOR}m<M>\e[m#{m.inspect}"
83
- @last_check[nest] = true
84
-
85
- nest.times do |column_number|
86
- print ((@last_check[column_number])? " " : "│ ") + " " * SPACE_SIZE
87
- end
88
- print "└─ ─ ── "
89
- nest += 1
90
- end
91
- end
92
-
93
- puts ( klass.kind_of?(Class) )? "\e[#{CCOLOR}m<C>\e[m#{klass.inspect}" : "\e[#{MCOLOR}m<M>\e[m#{klass.inspect}"
94
-
95
- subclasses.each do |sub|
96
- @last_check[nest] = true if sub == subclasses.last
97
-
98
- nest.times do |column_number|
99
- print ((@last_check[column_number])? " " : "│ ") + " " * SPACE_SIZE
100
- end
101
-
102
- if @tree.has_key?(sub)
103
- print ( sub == subclasses.last )? "└─ ─ ── " : "├─ ─ ── "
104
- if sub == subclasses.last
105
- draw_tree({ sub => @tree[sub]}, nest + 1, false, true)
106
- else
107
- draw_tree({ sub => @tree[sub]}, nest + 1, false, false)
108
- end
109
- else
110
- print ( sub == subclasses.last )? "└─ ─ ── " : "├─ ─ ── "
111
- nest_count = 0
112
- if( @mflag && sub.kind_of?(Class) )
113
- module_list = sub.ancestors[0..sub.ancestors.find_index(klass)-1].reverse - ([sub, klass] + sub.prepended_modules)
114
- @last_check[nest] = ( sub == subclasses.last )? true : false
115
-
116
- module_list.each_with_index do |m, add|
117
- puts "\e[#{MCOLOR}m<M>\e[m#{m.inspect}"
118
- @last_check[nest+add+1] = true
119
-
120
- (nest+add+1).times do |column_number|
121
- print ((@last_check[column_number])? " " : "│ ") + " " * SPACE_SIZE
122
- end
123
- print "└─ ─ ── "
124
- nest_count += 1
125
- end
126
- end
127
- puts ( sub.kind_of?(Class) )? "\e[#{CCOLOR}m<C>\e[m#{sub.inspect}" : "\e[#{MCOLOR}m<M>\e[m#{sub.inspect}"
128
-
129
- if ( @mflag && sub.kind_of?(Class) )
130
- prepended_modules = sub.prepended_modules
131
-
132
- prepended_modules.each_with_index do |m, add|
133
- (nest+nest_count+add+1).times do |column_number|
134
- print ((@last_check[column_number])? " " : "│ ") + " " * SPACE_SIZE
135
- end
136
- puts "└─ ─ ── \e[#{MCOLOR}m<M>\e[m#{m.inspect}"
137
- @last_check[nest+add+1] = true
138
- end
139
- end
140
- end
141
- end
142
- end
143
- end
144
- end
145
- end