object_tree 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eda02ea8be3269346e579f37b180697ed821b74f
4
- data.tar.gz: e926a68e49f4e365215057b9f78ecae18dceb572
3
+ metadata.gz: b30cc4942aec265a2dfbf49c18e230832ad33219
4
+ data.tar.gz: 178887b73d9d696305a3cc599a5d6ee37acb234a
5
5
  SHA512:
6
- metadata.gz: b1413d955e7103a77375561949d0845f8a8c229c8a2217dafd32bec46d4e4a3d01c95dcae2d7b52c71a7700a3d2642722b30664807cc70c92caade5baa1d1d67
7
- data.tar.gz: 1a23847e73c637de71eba4231b4e87f2636e360baf91bc840a44acd6d43a3fbf4d829041d5390bccd9a6cff8ff135790f24d186bf90144facac3380a6ea4d908
6
+ metadata.gz: b6974ad0855668d3fe755933e8f3db0fa246fab21898d63bb59cc216ea40d4c385cbd78f341e8ea6e06a9ff66540a70be1ad5704cc060198daf7916ddcaa0e34
7
+ data.tar.gz: df92457817a93efa8b98437b87d9017e49df00c4533feefdbc12a91ea45b8e4d10a59a30df1016e7dd56dfd0820691fe60d0295c8ee72ba4147522f61611f472
data/README.md CHANGED
@@ -79,6 +79,35 @@ output
79
79
  └───── <C> C
80
80
  ```
81
81
 
82
+ can use from terminal by using `rotree` command.
83
+
84
+ ```
85
+ $ rotree Numeric [master]
86
+ ```
87
+
88
+ Ruby 2.3.3
89
+
90
+ ```
91
+ <C> Numeric
92
+ ├───── <C> Complex
93
+ ├───── <C> Float
94
+ ├───── <C> Integer
95
+ │ ├───── <C> Bignum
96
+ │ └───── <C> Fixnum
97
+ └───── <C> Rational
98
+ ```
99
+
100
+ Ruby 2.4.0
101
+
102
+ ```
103
+ <C> Numeric
104
+ ├───── <C> Complex
105
+ ├───── <C> Float
106
+ ├───── <C> Integer
107
+ └───── <C> Rational
108
+ ```
109
+
110
+ you can see unify Fixnum and Bignum into Integer from ruby 2.4.0
82
111
 
83
112
  ## Contributing
84
113
 
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'object_tree'
4
+ require 'optparse'
5
+
6
+ options = { exclude: [], library: [] }
7
+
8
+ opt_parse = OptionParser.new do |opt|
9
+ opt.banner = 'Usage: rotree [options] klass'
10
+ opt.on('-c', '--[no-]color', 'color option [default true]') { |c| options[:color] = c }
11
+ opt.on('-e `klass`', '--exclude', 'Exclude the given class/module name from object_tree.') { |klass| options[:exclude] << klass }
12
+ opt.on('-r `library`', 'require the library before executing ObjectTree.create(klass)') { |name| options[:library] << name }
13
+ opt.on('-s `space size`', '--size', 'set indent space size [default 8]') { |s| options[:space_size] = s.to_i }
14
+ opt.parse!(ARGV)
15
+ end
16
+
17
+ options[:library].each {|r| eval("require '#{r}'") }
18
+
19
+ ObjectTree::OPTIONS.merge!(options)
20
+
21
+ if ARGV.first.nil?
22
+ puts opt_parse
23
+ else
24
+ klass = Object.const_get(ARGV.first.to_sym)
25
+ puts ObjectTree.create(klass)
26
+ end
@@ -1,6 +1,9 @@
1
1
  require 'colorize'
2
2
 
3
3
  class ObjectTree
4
+ attr_reader :tree
5
+
6
+ OPTIONS = { color: true, exclude: [], space_size: 8 }
4
7
  SPACE_SIZE = 8
5
8
  T_LINE = '├─────'
6
9
  I_LINE = '│'
@@ -11,12 +14,13 @@ class ObjectTree
11
14
  end
12
15
 
13
16
  def initialize(klass)
17
+ @tree = Hash.new {|h,k| h[k] = [] }
14
18
  @queue = []
15
19
  parse(klass)
16
20
  end
17
21
 
18
22
  def to_s
19
- @queue.join
23
+ OPTIONS[:color] ? @queue.join : @queue.join.uncolorize
20
24
  end
21
25
 
22
26
  def output_node(klass)
@@ -32,7 +36,7 @@ class ObjectTree
32
36
  end
33
37
 
34
38
  def get_space(end_line: nil)
35
- end_line ? ' ' * SPACE_SIZE : I_LINE + ' ' * (SPACE_SIZE-1)
39
+ end_line ? ' ' * OPTIONS[:space_size] : I_LINE + ' ' * (OPTIONS[:space_size]-1)
36
40
  end
37
41
 
38
42
  def parse(klass, space = '', path: [])
@@ -40,9 +44,9 @@ class ObjectTree
40
44
  modules = get_modules(klass, path.reverse)
41
45
  @queue << output_node(klass)
42
46
 
43
- until modules.empty?
44
- sub = modules.shift
45
-
47
+ while sub = modules.shift
48
+ next if OPTIONS[:exclude].include?(sub.to_s)
49
+ @tree[path.join('/')] << sub.to_s
46
50
  @queue << get_line(end_line: modules.empty?, space: space)
47
51
  parse(sub, space + get_space(end_line: modules.empty?), path: path.dup)
48
52
  end
@@ -54,6 +58,6 @@ class ObjectTree
54
58
  if l.each_cons(path.size).include?(path)
55
59
  (l[l.index(k)..l.index(klass)] - path).last
56
60
  end
57
- end.compact.uniq
61
+ end.compact.uniq.sort_by(&:to_s)
58
62
  end
59
63
  end
@@ -1,3 +1,3 @@
1
1
  class ObjectTree
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
4
5
  require 'object_tree/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
@@ -8,15 +9,19 @@ Gem::Specification.new do |spec|
8
9
  spec.version = ObjectTree::VERSION
9
10
  spec.authors = ["siman-man"]
10
11
  spec.email = ["k128585@ie.u-ryukyu.ac.jp"]
12
+
11
13
  spec.description = "like tree command for Ruby ancestors."
12
14
  spec.summary = "like tree command for Ruby ancestors."
13
15
  spec.homepage = "https://github.com/siman-man/object_tree"
14
16
  spec.license = "MIT"
15
17
  spec.required_ruby_version = '>= 2.0.0'
16
18
 
17
- spec.files = `git ls-files`.split($/)
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
25
  spec.require_paths = ["lib"]
21
26
 
22
27
  spec.add_dependency 'colorize'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - siman-man
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-28 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -69,7 +69,8 @@ dependencies:
69
69
  description: like tree command for Ruby ancestors.
70
70
  email:
71
71
  - k128585@ie.u-ryukyu.ac.jp
72
- executables: []
72
+ executables:
73
+ - rotree
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
@@ -80,12 +81,10 @@ files:
80
81
  - LICENSE.txt
81
82
  - README.md
82
83
  - Rakefile
84
+ - exe/rotree
83
85
  - lib/object_tree.rb
84
86
  - lib/object_tree/version.rb
85
87
  - object_tree.gemspec
86
- - spec/fixtures/example.rb
87
- - spec/object_tree_spec.rb
88
- - spec/spec_helper.rb
89
88
  homepage: https://github.com/siman-man/object_tree
90
89
  licenses:
91
90
  - MIT
@@ -110,7 +109,4 @@ rubygems_version: 2.6.10
110
109
  signing_key:
111
110
  specification_version: 4
112
111
  summary: like tree command for Ruby ancestors.
113
- test_files:
114
- - spec/fixtures/example.rb
115
- - spec/object_tree_spec.rb
116
- - spec/spec_helper.rb
112
+ test_files: []
@@ -1,72 +0,0 @@
1
- module Case1
2
- class A
3
- end
4
-
5
- class B < A
6
- end
7
-
8
- class C < B
9
- end
10
- end
11
-
12
- module Case2
13
- module A
14
- end
15
-
16
- class B
17
- include A
18
- end
19
- end
20
-
21
- module Case3
22
- class A
23
- end
24
-
25
- class B < A
26
- end
27
-
28
- class C < A
29
- end
30
- end
31
-
32
- module Case4
33
- module D
34
- end
35
-
36
- module E
37
- end
38
-
39
- class A
40
- include D
41
- end
42
-
43
- class B < A
44
- end
45
-
46
- class C < A
47
- include E
48
- end
49
- end
50
-
51
- module Case5
52
- module D
53
- end
54
-
55
- module E
56
- end
57
-
58
- class A
59
- include D
60
- end
61
-
62
- class B < A
63
- end
64
-
65
- class C < A
66
- include E
67
- end
68
-
69
- class F < B
70
- include E
71
- end
72
- end
@@ -1,60 +0,0 @@
1
- require 'fixtures/example'
2
-
3
- describe ObjectTree do
4
- describe 'examples' do
5
- it 'test case 1' do
6
- expect =<<-EXPECT
7
- <C> Case1::A
8
- └───── <C> Case1::B
9
- └───── <C> Case1::C
10
- EXPECT
11
-
12
- expect(ObjectTree.create(Case1::A).to_s.uncolorize).to eq(expect)
13
- end
14
-
15
- it 'test case 2' do
16
- expect =<<-EXPECT
17
- <M> Case2::A
18
- └───── <C> Case2::B
19
- EXPECT
20
-
21
- expect(ObjectTree.create(Case2::A).to_s.uncolorize).to eq(expect)
22
- end
23
-
24
- it 'test case 3' do
25
- expect =<<-EXPECT
26
- <C> Case3::A
27
- ├───── <C> Case3::C
28
- └───── <C> Case3::B
29
- EXPECT
30
-
31
- expect(ObjectTree.create(Case3::A).to_s.uncolorize).to eq(expect)
32
- end
33
-
34
- it 'test case 4' do
35
- expect =<<-EXPECT
36
- <M> Case4::D
37
- └───── <C> Case4::A
38
- ├───── <M> Case4::E
39
- │ └───── <C> Case4::C
40
- └───── <C> Case4::B
41
- EXPECT
42
-
43
- expect(ObjectTree.create(Case4::D).to_s.uncolorize).to eq(expect)
44
- end
45
-
46
- it 'test case 5' do
47
- expect =<<-EXPECT
48
- <M> Case5::D
49
- └───── <C> Case5::A
50
- ├───── <C> Case5::B
51
- │ └───── <M> Case5::E
52
- │ └───── <C> Case5::F
53
- └───── <M> Case5::E
54
- └───── <C> Case5::C
55
- EXPECT
56
-
57
- expect(ObjectTree.create(Case5::D).to_s.uncolorize).to eq(expect)
58
- end
59
- end
60
- end
@@ -1,106 +0,0 @@
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
- # The generated `.rspec` file contains `--require spec_helper` which will cause
4
- # this file to always be loaded, without a need to explicitly require it in any
5
- # files.
6
- #
7
- # Given that it is always loaded, you are encouraged to keep this file as
8
- # light-weight as possible. Requiring heavyweight dependencies from this file
9
- # will add to the boot time of your test suite on EVERY test run, even for an
10
- # individual file that may not need all of that loaded. Instead, consider making
11
- # a separate helper file that requires the additional dependencies and performs
12
- # the additional setup, and require it from the spec files that actually need
13
- # it.
14
- #
15
- # The `.rspec` file also contains a few flags that are not defaults but that
16
- # users commonly want.
17
- #
18
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
-
20
- require 'object_tree'
21
-
22
- RSpec.configure do |config|
23
- # rspec-expectations config goes here. You can use an alternate
24
- # assertion/expectation library such as wrong or the stdlib/minitest
25
- # assertions if you prefer.
26
- config.expect_with :rspec do |expectations|
27
- # This option will default to `true` in RSpec 4. It makes the `description`
28
- # and `failure_message` of custom matchers include text for helper methods
29
- # defined using `chain`, e.g.:
30
- # be_bigger_than(2).and_smaller_than(4).description
31
- # # => "be bigger than 2 and smaller than 4"
32
- # ...rather than:
33
- # # => "be bigger than 2"
34
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
- end
36
-
37
- # rspec-mocks config goes here. You can use an alternate test double
38
- # library (such as bogus or mocha) by changing the `mock_with` option here.
39
- config.mock_with :rspec do |mocks|
40
- # Prevents you from mocking or stubbing a method that does not exist on
41
- # a real object. This is generally recommended, and will default to
42
- # `true` in RSpec 4.
43
- mocks.verify_partial_doubles = true
44
- end
45
-
46
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
47
- # have no way to turn it off -- the option exists only for backwards
48
- # compatibility in RSpec 3). It causes shared context metadata to be
49
- # inherited by the metadata hash of host groups and examples, rather than
50
- # triggering implicit auto-inclusion in groups with matching metadata.
51
- config.shared_context_metadata_behavior = :apply_to_host_groups
52
-
53
- # The settings below are suggested to provide a good initial experience
54
- # with RSpec, but feel free to customize to your heart's content.
55
- =begin
56
- # This allows you to limit a spec run to individual examples or groups
57
- # you care about by tagging them with `:focus` metadata. When nothing
58
- # is tagged with `:focus`, all examples get run. RSpec also provides
59
- # aliases for `it`, `describe`, and `context` that include `:focus`
60
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
61
- config.filter_run_when_matching :focus
62
-
63
- # Allows RSpec to persist some state between runs in order to support
64
- # the `--only-failures` and `--next-failure` CLI options. We recommend
65
- # you configure your source control system to ignore this file.
66
- config.example_status_persistence_file_path = "spec/examples.txt"
67
-
68
- # Limits the available syntax to the non-monkey patched syntax that is
69
- # recommended. For more details, see:
70
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
71
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
73
- config.disable_monkey_patching!
74
-
75
- # This setting enables warnings. It's recommended, but in some cases may
76
- # be too noisy due to issues in dependencies.
77
- config.warnings = true
78
-
79
- # Many RSpec users commonly either run the entire suite or an individual
80
- # file, and it's useful to allow more verbose output when running an
81
- # individual spec file.
82
- if config.files_to_run.one?
83
- # Use the documentation formatter for detailed output,
84
- # unless a formatter has already been configured
85
- # (e.g. via a command-line flag).
86
- config.default_formatter = 'doc'
87
- end
88
-
89
- # Print the 10 slowest examples and example groups at the
90
- # end of the spec run, to help surface which specs are running
91
- # particularly slow.
92
- config.profile_examples = 10
93
-
94
- # Run specs in random order to surface order dependencies. If you find an
95
- # order dependency and want to debug it, you can fix the order by providing
96
- # the seed, which is printed after each run.
97
- # --seed 1234
98
- config.order = :random
99
-
100
- # Seed global randomization in this process using the `--seed` CLI option.
101
- # Setting this allows you to use `--seed` to deterministically reproduce
102
- # test failures related to randomization by passing the same `--seed` value
103
- # as the one that triggered the failure.
104
- Kernel.srand config.seed
105
- =end
106
- end