hierarchy_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca878b79ffaca8589071ed86b8cb55f41f77527c
4
+ data.tar.gz: 80e9136649089bc11fdf19915b9ab578e926e224
5
+ SHA512:
6
+ metadata.gz: f33bfec33eb270f4dee6bcf3da3ec6a70c00c4bab5925d468a43f43c9519dd9315140305a7210bfd714a72803796cfacc725b4917e83a1882bad328be14f5bdc
7
+ data.tar.gz: 8c4f6e7222be156703d5591eb267cb4e28d7a1b1cbc5520b96585c2e2e930b939f25700871c5f6bffd15da78028593e1cde28d667ea31c8c23a8d3520c2d250c
@@ -0,0 +1,22 @@
1
+ #!/home/yeshuai/.rvm/rubies/ruby-2.0.0-p598/bin/ruby
2
+
3
+ require 'hierarchy_generator'
4
+
5
+ # for Ruby 2.0
6
+ class HierarchyGenerator
7
+
8
+ def self.g_class_methods(flag=nil)
9
+ Generator.g_class_methods(flag)
10
+ end
11
+
12
+ def self.g_module_methods(flag=nil)
13
+ Generator.g_module_methods(flag)
14
+ end
15
+
16
+ def self.g_all_methods(c_flag=nil, m_flag=nil)
17
+ Generator.g_module_methods(m_flag)
18
+ Generator.g_class_methods(c_flag)
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'hierarchy_generator/generator'
4
+
5
+ # for Ruby 2.0
6
+
7
+ arg = ARGV[0]
8
+
9
+ if arg == "class"
10
+ HierarchyGenerator::Generator.g_class_methods(ARGV[1])
11
+ elsif arg == "module"
12
+ HierarchyGenerator::Generator.g_module_methods(ARGV[1])
13
+ elsif arg == "all"
14
+ HierarchyGenerator::Generator.g_module_methods(ARGV[1])
15
+ HierarchyGenerator::Generator.g_class_methods(ARGV[2])
16
+ else
17
+ puts "参数不正确"
18
+ exit 0
19
+ end
@@ -0,0 +1,100 @@
1
+ require 'hierarchy_generator/monkey_patch'
2
+
3
+ # ruby 2.0
4
+ class HierarchyGenerator
5
+
6
+ class MyTopClass; end
7
+ class MyTopModule; end
8
+
9
+
10
+ # all classes
11
+ # [:Array, :BasicObject, :Bignum, :Binding, :Class, :Complex, :ConditionVariable, :Data, :Dir, :Encoding, :Enumerator, :FalseClass, :Fiber, :File, :Fixnum, :Float, :Hash, :IO, :Integer, :MatchData, :Method, :Module, :Monitor, :Mutex, :NilClass, :Numeric, :Object, :Proc, :Queue, :Random, :Range, :Rational, :Regexp, :RubyLex, :RubyVM, :SizedQueue, :String, :Struct, :Symbol, :Thread, :ThreadGroup, :Time, :TracePoint, :TrueClass, :UnboundMethod]
12
+
13
+ # all exceptions
14
+ # [:ArgumentError, :EOFError, :EncodingError, :Exception, :FiberError, :FloatDomainError, :IOError, :IndexError, :Interrupt, :KeyError, :LoadError, :LocalJumpError, :NameError, :NoMemoryError, :NoMethodError, :NotImplementedError, :RangeError, :RegexpError, :RuntimeError, :ScriptError, :SecurityError, :SignalException, :StandardError, :StopIteration, :SyntaxError, :SystemCallError, :SystemExit, :SystemStackError, :ThreadError, :TypeError, :ZeroDivisionError]
15
+
16
+ MyTopClass.adopt(BasicObject)
17
+ BasicObject.adopt(Object)
18
+ Object.adopt(Array, Binding, ConditionVariable, Data, Dir, Data, Encoding, Enumerator, Exception, FalseClass, Fiber, Hash, IO, MatchData, Method, Module, Monitor, Mutex, NilClass, Numeric, Proc, Queue, Random, Range, Regexp, RubyVM, String, Struct, Symbol, Thread, ThreadGroup, Time, TracePoint, TrueClass, UnboundMethod)
19
+ IO.adopt(File)
20
+ Module.adopt(Class)
21
+ Queue.adopt(SizedQueue)
22
+ Numeric.adopt(Integer, Float, Complex, Rational)
23
+ Integer.adopt(Bignum, Fixnum)
24
+
25
+ Exception.adopt(NoMemoryError, ScriptError, SecurityError, SignalException, SystemExit, SystemStackError, StandardError)
26
+ ScriptError.adopt(LoadError, NotImplementedError, SyntaxError)
27
+ SignalException.adopt(Interrupt)
28
+ StandardError.adopt(ArgumentError, EncodingError, FiberError, IOError, IndexError, NameError, RangeError, RegexpError, RuntimeError, SystemCallError, ThreadError, TypeError, ZeroDivisionError)
29
+ IOError.adopt(EOFError)
30
+ IndexError.adopt(KeyError, StopIteration, LocalJumpError)
31
+ NameError.adopt(NoMethodError)
32
+ RangeError.adopt(FloatDomainError)
33
+
34
+ # all modules
35
+ # [:Comparable, :Config, :Enumerable, :Errno, :Exception2MessageMapper, :FileTest, :GC, :Gem, :IRB, :Kernel, :Marshal, :Math, :MonitorMixin, :ObjectSpace, :Process, :RbConfig, :Readline, :RubyToken, :Signal]
36
+
37
+ MyTopModule.adopt(Comparable, Enumerable, Errno, FileTest, GC, Gem, Kernel, Marshal, Math, MonitorMixin, ObjectSpace, Process, RbConfig, Signal)
38
+
39
+ # all relationships on ready
40
+
41
+ class Generator
42
+
43
+ extend FileUtils::Verbose
44
+
45
+ def self.mkdirs(parent, flag=nil)
46
+ if parent.class == Module
47
+ parent.subs.each { |m| generate_methods(m) }
48
+ else
49
+ if parent.subs
50
+ parent.subs.each do |child|
51
+ generate_methods(child, flag)
52
+ if child.subs
53
+ cd("#{child.to_s}#{flag}")
54
+ mkdirs(child, flag)
55
+ cd("..")
56
+ end
57
+ end
58
+ else
59
+ generate_methods(parent, flag)
60
+ end
61
+ end
62
+ end
63
+
64
+ def self.generate_methods(c, flag=nil)
65
+ mkdir_p("#{c.to_s}#{flag}")
66
+ cd("#{c.to_s}#{flag}")
67
+ g_ms(c) # if you only want to generate Class(Module)'s hierarchies, comment this line
68
+ cd("..")
69
+ end
70
+
71
+ def self.g_ms(c)
72
+ ["____instance_methods", "____private_instance_methods", "____singleton_methods"].each do |m_name|
73
+ m = m_name[4..-1]
74
+ if c.respond_to? m
75
+ mkdir_p(m_name)
76
+ cd(m_name)
77
+ c.send(m, false).each do |n|
78
+ `touch #{n}`
79
+ end
80
+ cd("..")
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.g_class_methods(c_flag)
86
+ mkdirs(MyTopClass, c_flag)
87
+ end
88
+
89
+ def self.g_module_methods(m_flag)
90
+ mkdirs(MyTopModule, m_flag)
91
+ end
92
+
93
+ def self.g_all_methods(c_flag, m_flag)
94
+ mkdirs(MyTopModule, m_flag)
95
+ mkdirs(MyTopClass, c_flag)
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,13 @@
1
+ class Class
2
+ attr :subs
3
+ def adopt(*c)
4
+ @subs = c
5
+ end
6
+ end
7
+
8
+ class Module
9
+ attr :subs
10
+ def adopt(*m)
11
+ @subs = m
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hierarchy_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yeshuai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 这个 Ruby 命令会生成 ruby 体系结构,每个类或者模块都会是一个目录,每一个 method 都是一个空的纯文本文件
14
+ email: shenyangyeshuai@gmail.com
15
+ executables:
16
+ - hierarchy_generator
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/hierarchy_generator
21
+ - lib/hierarchy_generator.rb
22
+ - lib/hierarchy_generator/generator.rb
23
+ - lib/hierarchy_generator/monkey_patch.rb
24
+ homepage: https://github.com/shenyangyeshuai/hierarchy_generator
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.4.3
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Ruby 体系结构的目录生成树
48
+ test_files: []