pry-aa_ancestors 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be725f14f271ac18dede92acd65b959c7c351a5e
4
+ data.tar.gz: 136fdbd17b72be53e63d6ab8106b15eec8ef2505
5
+ SHA512:
6
+ metadata.gz: 8b49936bf423015b113296858814ff4acec451bef5c5b1c5c1f6adf0c47c16e0a4ca01f12f2656b75067e2fd29fac850e481e9e3aba5cba5d30f1eafb2bdbd9d
7
+ data.tar.gz: 71b003fb1d0e8f9f69ad597fb3e7b75906546a40378aac6f8ac70f2904843d58c4a652076f6d918419bec4bdd6e4a6bee5ef8d7f3541de6c8547907d78403d49
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pry-aa_ancestors.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 tbpgr
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.
@@ -0,0 +1,149 @@
1
+ # PryAaAncestors
2
+
3
+ PryAaAncestors is :link:[pry](https://github.com/pry/pry) plugin.
4
+ Show the class hierarchy that is ascii-art format.
5
+
6
+ ~~~
7
+ % pry
8
+ [1] pry(main)> require 'prime'
9
+ => true
10
+ [2] pry(main)> aa_ancestors Prime
11
+ -----------------
12
+ | BasicObject |
13
+ -----------------
14
+ |
15
+ -----------------
16
+ | Kernel |
17
+ -----------------
18
+ |
19
+ -----------------
20
+ |PP::ObjectMixin|
21
+ -----------------
22
+ |
23
+ -----------------
24
+ | Object |
25
+ -----------------
26
+ |
27
+ -----------------
28
+ | Enumerable |
29
+ -----------------
30
+ |
31
+ -----------------
32
+ | Prime |
33
+ -----------------
34
+ ~~~
35
+
36
+ ## :cloud::arrow_down: Installation
37
+
38
+ Add this line to your application's Gemfile:
39
+
40
+ ```ruby
41
+ gem 'pry-aa_ancestors'
42
+ ```
43
+
44
+ And then execute:
45
+
46
+ $ bundle
47
+
48
+ Or install it yourself as:
49
+
50
+ $ gem install pry-aa_ancestors
51
+
52
+ ## :scroll: Usage
53
+ ### :ballot_box_with_check: Confirm Installation
54
+
55
+ ~~~
56
+ $ pry --plugins
57
+ Installed Plugins:
58
+ --
59
+ aa_ancestors Show the class hierarchy that is Ascii-Art format.
60
+ ~~~
61
+
62
+ ### :closed_book: Help
63
+ ~~~bash
64
+ $ pry
65
+ [1] pry(main)> help aa_ancestors
66
+ Show the class hierarchy that is Ascii-Art format.
67
+ -h, --help Show this message.
68
+ ~~~
69
+
70
+ ### :older_man::man::boy::baby: Standard class ( String ) hierarchy
71
+ ~~~bash
72
+ $ pry
73
+ [2] pry(main)> aa_ancestors String
74
+ -----------------
75
+ | BasicObject |
76
+ -----------------
77
+ |
78
+ -----------------
79
+ | Kernel |
80
+ -----------------
81
+ |
82
+ -----------------
83
+ |PP::ObjectMixin|
84
+ -----------------
85
+ |
86
+ -----------------
87
+ | Object |
88
+ -----------------
89
+ |
90
+ -----------------
91
+ | Comparable |
92
+ -----------------
93
+ |
94
+ -----------------
95
+ | String |
96
+ -----------------
97
+ ~~~
98
+
99
+ ### :older_woman::woman::girl::baby: User defined class ( Child ) hierarchy
100
+
101
+ ~~~bash
102
+ $ pry
103
+ [1] pry(main)> module Extendable
104
+ [1] pry(main)* end
105
+ => nil
106
+ [2] pry(main)> class Parent
107
+ [2] pry(main)* end d
108
+ => nil
109
+ [3] pry(main)> class Child < Parent
110
+ [3] pry(main)* include Extendable
111
+ [3] pry(main)* end d
112
+ => Child
113
+ [4] pry(main)> aa_ancestors Child
114
+ -----------------
115
+ | BasicObject |
116
+ -----------------
117
+ |
118
+ -----------------
119
+ | Kernel |
120
+ -----------------
121
+ |
122
+ -----------------
123
+ |PP::ObjectMixin|
124
+ -----------------
125
+ |
126
+ -----------------
127
+ | Object |
128
+ -----------------
129
+ |
130
+ -----------------
131
+ | Parent |
132
+ -----------------
133
+ |
134
+ -----------------
135
+ | Extendable |
136
+ -----------------
137
+ |
138
+ -----------------
139
+ | Child |
140
+ -----------------
141
+ ~~~
142
+
143
+ ## :two_men_holding_hands: Contributing :two_women_holding_hands:
144
+
145
+ 1. Fork it ( https://github.com/tbpgr/pry-aa_ancestors/fork )
146
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
147
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
148
+ 4. Push to the branch (`git push origin my-new-feature`)
149
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module PryAaAncestors
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,151 @@
1
+ require "pry"
2
+
3
+ # String
4
+ class String
5
+ # surround string.
6
+ #
7
+ # ==== Options
8
+ #
9
+ # * <tt>:top_bottom</tt> - set top and bottom charactor
10
+ # * <tt>:side</tt> - set right and left charactor
11
+ #
12
+ # ==== Examples
13
+ #
14
+ # single line, no option case
15
+ #
16
+ # 'hoge'.surround
17
+ #
18
+ # result
19
+ #
20
+ # ------
21
+ # |hoge|
22
+ # ------
23
+ #
24
+ # multi line, no option case
25
+ #
26
+ # "hoge\na".surround
27
+ #
28
+ # result
29
+ #
30
+ # ------
31
+ # |hoge|
32
+ # |a |
33
+ # ------
34
+ #
35
+ # single line, both option case
36
+ #
37
+ # 'hoge'.surround top_bottom: '=', side: '!'
38
+ #
39
+ # result
40
+ #
41
+ # ======
42
+ # !hoge!
43
+ # ======
44
+ #
45
+ def surround(options = { top_bottom: '-', side: '|' })
46
+ top_bottom = init_top_bottom(options)
47
+ side = init_side(options)
48
+ inner_width = line_max
49
+ top_bottom = top_bottoms(top_bottom, inner_width)
50
+ ret = *each_line.reduce([top_bottom]) do |a, e|
51
+ a << "#{side}#{e.chomp.ljust(inner_width)}#{side}"
52
+ end
53
+ ret.push(top_bottom).join("\n")
54
+ end
55
+
56
+ private
57
+
58
+ def init_top_bottom(options)
59
+ options[:top_bottom].nil? ? '-' : options[:top_bottom]
60
+ end
61
+
62
+ def init_side(options)
63
+ options[:side].nil? ? '|' : options[:side]
64
+ end
65
+
66
+ def top_bottoms(top_bottom, inner_width)
67
+ top_bottom * (inner_width + 2)
68
+ end
69
+
70
+ def line_max
71
+ return 0 if self.empty?
72
+ each_line.max_by(&:size).chomp.size
73
+ end
74
+ end
75
+
76
+ # Kernel
77
+ module Kernel
78
+ # Ascii Art Ancestors
79
+ #
80
+ # === Examples
81
+ #
82
+ # define class
83
+ #
84
+ # class BaseHogeForAncestors;end
85
+ # class HogeForAncestors < BaseHogeForAncestors;end
86
+ #
87
+ # execute aa_ancestors
88
+ #
89
+ # puts HogeForAncestors.aa_ancestors
90
+ #
91
+ # result is ...
92
+ #
93
+ # ----------------------
94
+ # | BasicObject |
95
+ # ----------------------
96
+ # |
97
+ # ----------------------
98
+ # | Kernel |
99
+ # ----------------------
100
+ # |
101
+ # ----------------------
102
+ # | Object |
103
+ # ----------------------
104
+ # |
105
+ # ----------------------
106
+ # |BaseHogeForAncestors|
107
+ # ----------------------
108
+ # |
109
+ # ----------------------
110
+ # | HogeForAncestors |
111
+ # ----------------------
112
+ def aa_ancestors
113
+ max_class = max_size_class
114
+ max = max_class.to_s.size
115
+ ca = centered_ancestors(max)
116
+ ba = surrounded_ancestors(ca)
117
+ connected_box_ancestors(ba, max)
118
+ end
119
+
120
+ private
121
+
122
+ def max_size_class
123
+ ancestors.max_by { |v|v.to_s.size }
124
+ end
125
+
126
+ def centered_ancestors(max)
127
+ ancestors.reverse.map { |v|v.to_s.center max }
128
+ end
129
+
130
+ def surrounded_ancestors(ca)
131
+ ca.reduce([]) { |a, e|a << e.surround }
132
+ end
133
+
134
+ def connected_box_ancestors(ba, max)
135
+ ba.join(ancestors_connector(max))
136
+ end
137
+
138
+ def ancestors_connector(max)
139
+ connector = '|'.rjust((max + 2) / 2)
140
+ "\n#{connector}\n"
141
+ end
142
+ end
143
+
144
+ Pry::Commands.create_command 'aa_ancestors' do
145
+ description 'Show the class hierarchy that is Ascii-Art format.'
146
+
147
+ def process(klass)
148
+ target = eval klass, binding
149
+ output.puts(target.aa_ancestors)
150
+ end
151
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aa_ancestors/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pry-aa_ancestors"
8
+ spec.version = PryAaAncestors::VERSION
9
+ spec.authors = ["tbpgr"]
10
+ spec.email = ["tbpgr@tbpgr.jp"]
11
+ spec.summary = %q{Show the class hierarchy that is Ascii-Art format.}
12
+ spec.description = %q{Show the class hierarchy that is Ascii-Art format.}
13
+ spec.homepage = "https://github.com/tbpgr/pry-aa_ancestors"
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 "pry"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-aa_ancestors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Show the class hierarchy that is Ascii-Art format.
56
+ email:
57
+ - tbpgr@tbpgr.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/aa_ancestors/version.rb
68
+ - lib/pry-aa_ancestors.rb
69
+ - pry-aa_ancestors.gemspec
70
+ homepage: https://github.com/tbpgr/pry-aa_ancestors
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.3.0
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Show the class hierarchy that is Ascii-Art format.
94
+ test_files: []
95
+ has_rdoc: