method_reflect 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzFiYzViNDE4NjUzZTMwYTdkMjNkYzViZmE0MGJhNTVlZmMwNzdiMA==
5
+ data.tar.gz: !binary |-
6
+ MWEzMzFjZWY0M2I5YjA4NTRhZDdjOTQ5ODY3Y2Q4Y2ViMGM5NjUxNQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZjQxZWZkMWU2YjI3NWYxNTZjM2Y2YzM1OTdhZTZmNWI4ZTdmNjhhNmM1ZmY3
10
+ NjFkODEzOWI4ZTFmZDI4Njk3ZTMzNWIxZTA2ZWVjNDk3NjdjMjNkNTM0ZWQy
11
+ ZDU5Njg1MDgzODE5MTZmOWNkOTgxMzgxNWM2NGU5NzZjOTJiZGE=
12
+ data.tar.gz: !binary |-
13
+ OGNjOThiODhjODAxNjJhMzZmMDI4MjNlZWFlY2JlNjc1NDQ0NGY3NDc4Y2Q5
14
+ ZTFkN2NlZTQ3ZWRjOTYwNDA5YmRmMzJjYTIwZDIwYzNiYTdiM2IwNDIyMDM4
15
+ MmViNzJjYjlhZGZjYTczZTRmOGQwZGRkYTA5NmMwZmJiZDcxYTE=
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Danny Purcell
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,34 @@
1
+ Method Reflect
2
+ ---------------
3
+
4
+ © Danny Purcell 2013 | MIT license
5
+
6
+ Gives Ruby Methods some deeper self-knowledge.
7
+
8
+ Features
9
+ ---------------
10
+
11
+ Loading this gem adds several instance methods to the core Method class so methods can tell you more about themselves.
12
+
13
+ Leverages [YARD](https://github.com/lsegal/yard) and [method_source](https://github.com/banister/method_source) to
14
+ provide easy access to everything you might want to know about a method.
15
+
16
+
17
+ Installation
18
+ ---------------
19
+
20
+ #### Install with Gem
21
+ * Available on [Rubygems](https://rubygems.org/gems/method_reflect)
22
+ * Be sure one of your gem sources is `source 'https://rubygems.org'`
23
+ * Run `gem install rubycom`
24
+
25
+ #### Building locally
26
+ * Fork the repository if you wish
27
+ * Clone repository locally
28
+ * If using the main repo: `git clone https://github.com/dannypurcell/method_reflect.git`
29
+ * Run `rake install` if installing for the first time
30
+ * If updating to the latest version run the following commands
31
+ * `git checkout master`
32
+ * `git pull origin master`
33
+ * If that causes any problems `git reset --hard origin/master`
34
+ * `rake upgrade`
@@ -0,0 +1,74 @@
1
+ require 'yard'
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:package]
5
+
6
+ task :clean do
7
+ FileUtils.rm_rf('./doc')
8
+ FileUtils.rm_rf('./.yardoc')
9
+ FileUtils.rm_rf('./pkg')
10
+ FileUtils.rm(Dir.glob('./*-*.gem'))
11
+ end
12
+
13
+ task :bundle do
14
+ system('bundle install')
15
+ end
16
+
17
+ Rake::TestTask.new do |t|
18
+ t.libs << 'test'
19
+ t.test_files = FileList['test/*/*_test.rb']
20
+ t.verbose = true
21
+ end
22
+
23
+ YARD::Rake::YardocTask.new
24
+
25
+ task :package => [:clean, :bundle, :test, :yard] do
26
+ gem_specs = Dir.glob('**/*.gemspec')
27
+ gem_specs.each { |gem_spec|
28
+ system("gem build #{gem_spec}")
29
+ raise 'Error during build phase' if $?.exitstatus != 0
30
+ }
31
+ end
32
+
33
+ task :install => :package do
34
+ load "#{File.expand_path(File.dirname(__FILE__))}/lib/method_reflect/version.rb"
35
+ system("gem install #{File.expand_path(File.dirname(__FILE__))}/method_reflect-#{MethodReflect::VERSION}.gem")
36
+ end
37
+
38
+ task :upgrade => :package do
39
+ system('gem uninstall method_reflect -a')
40
+ load "#{File.expand_path(File.dirname(__FILE__))}/lib/method_reflect/version.rb"
41
+ system("gem install #{File.expand_path(File.dirname(__FILE__))}/method-reflect-#{MethodReflect::VERSION}.gem")
42
+ end
43
+
44
+ task :version_set, [:version] do |_, args|
45
+ raise "Must provide a version.\n If you called 'rake version_set 1.2.3', try 'rake version_set[1.2.3]'" if args[:version].nil? || args[:version].empty?
46
+
47
+ version_file = <<-END.gsub(/^ {4}/, '')
48
+ module MethodReflect
49
+ VERSION = "#{args[:version]}"
50
+ end
51
+ END
52
+ puts "Writing version file:\n #{version_file}"
53
+ File.open("#{File.expand_path(File.dirname(__FILE__))}/lib/method_reflect/version.rb", 'w+') { |file|
54
+ file.write(version_file)
55
+ }
56
+ file_text = File.read("#{File.expand_path(File.dirname(__FILE__))}/lib/method_reflect/version.rb")
57
+ raise 'Could not update version file' if file_text != version_file
58
+ end
59
+
60
+ task :release, [:version] => [:version_set, :package] do |_, args|
61
+ system('git clean -f')
62
+ system('git add .')
63
+ system("git commit -m\"Version to #{args[:version]}\"")
64
+ if $?.exitstatus == 0
65
+ system("git tag -a v#{args[:version]} -m\"Version #{args[:version]} Release\"")
66
+ if $?.exitstatus == 0
67
+ system('git push origin master --tags')
68
+ if $?.exitstatus == 0
69
+ load "#{File.expand_path(File.dirname(__FILE__))}/lib/method_reflect/version.rb"
70
+ system("gem push #{File.expand_path(File.dirname(__FILE__))}/method_reflect-#{MethodReflect::VERSION}.gem")
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,88 @@
1
+ require 'method_source'
2
+ require 'yard'
3
+
4
+ module MethodReflect
5
+ module MethodExtensions
6
+
7
+ def commented_source
8
+ if @commented_source == nil
9
+ @commented_source = self.comment + self.source
10
+ end
11
+ @commented_source
12
+ end
13
+
14
+ def code_object
15
+ if @code_object == nil
16
+ YARD::Registry.clear
17
+ YARD::parse_string(commented_source)
18
+ @code_object = YARD::Registry.first
19
+ end
20
+ @code_object
21
+ end
22
+
23
+ def docstring
24
+ if @docstring == nil
25
+ @docstring = code_object.docstring
26
+ end
27
+ @docstring
28
+ end
29
+
30
+ def docstring_summary
31
+ if @docstring_summary == nil
32
+ @docstring_summary = code_object.docstring.summary
33
+ end
34
+ @docstring_summary
35
+ end
36
+
37
+ def docstring_tags
38
+ if @docstring_tags == nil
39
+ @docstring_tags = docstring.tags.map { |t|
40
+ {name: t.name, tag_name: t.tag_name, text: t.text, types: t.types}
41
+ }
42
+ end
43
+ @docstring_tags
44
+ end
45
+
46
+ def signature
47
+ if @signature == nil
48
+ @signature = code_object.signature
49
+ end
50
+ @signature
51
+ end
52
+
53
+ def parameter_defaults
54
+ if @parameter_defaults == nil
55
+ @parameter_defaults = code_object.parameters.map{|n,d| [n.to_sym, d]}
56
+ end
57
+ @parameter_defaults
58
+ end
59
+
60
+ def visibility
61
+ if @visibility == nil
62
+ @visibility = code_object.visibility
63
+ end
64
+ @visibility
65
+ end
66
+
67
+ def scope
68
+ if @scope == nil
69
+ @scope = code_object.scope
70
+ end
71
+ @scope
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ class Method
79
+ include MethodReflect::MethodExtensions
80
+ end
81
+
82
+ class UnboundMethod
83
+ include MethodReflect::MethodExtensions
84
+ end
85
+
86
+ class Proc
87
+ include MethodReflect::MethodExtensions
88
+ end
@@ -0,0 +1,3 @@
1
+ module MethodReflect
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require "#{File.dirname(__FILE__)}/lib/method_reflect/version.rb"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'method_reflect'
5
+ spec.version = MethodReflect::VERSION
6
+ spec.authors = ['Danny Purcell']
7
+ spec.email = %w(d.purcell.jr+method_reflect@gmail.com)
8
+ spec.description = %q{Adds several instance methods to the core Method class so methods can tell you more about themselves.}
9
+ spec.summary = %q{Gives Ruby Methods some deeper self-knowledge}
10
+ spec.homepage = 'http://dannypurcell.github.io/method_reflect'
11
+ spec.license = 'MIT'
12
+
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = %w(lib)
17
+
18
+ spec.add_development_dependency 'bundler'
19
+ spec.add_development_dependency 'test-unit'
20
+ spec.add_development_dependency 'rake'
21
+ spec.add_dependency 'method_source', '~> 0.8.2'
22
+ spec.add_dependency 'yard', '~> 0.8.7.6'
23
+ end
@@ -0,0 +1,133 @@
1
+ require "#{File.dirname(__FILE__)}/../lib/method_reflect.rb"
2
+
3
+ require 'test/unit'
4
+
5
+ class MethodReflectTest < Test::Unit::TestCase
6
+ class TestClass
7
+ # A test method
8
+ #
9
+ # @param a [String] a string param
10
+ # @param b [String] an array param
11
+ # @param c [String] a hash param
12
+ # @param d [String] the rest of the params
13
+ def test_method a, b=[], c={x: 1, y: 2}, *d, &e
14
+ @args = [a, b, c, d, e]
15
+ puts "#{@args}"
16
+ end
17
+ end
18
+
19
+ def test_commented_source_method
20
+ expected = <<-END.gsub(/^ {6}/, '')
21
+ # A test method
22
+ #
23
+ # @param a [String] a string param
24
+ # @param b [String] an array param
25
+ # @param c [String] a hash param
26
+ # @param d [String] the rest of the params
27
+ def test_method a, b=[], c={x: 1, y: 2}, *d, &e
28
+ @args = [a, b, c, d, e]
29
+ puts "\#{@args}"
30
+ end
31
+ END
32
+
33
+ result = TestClass.new.method(:test_method).commented_source
34
+
35
+ expected_lines = expected.split("\n").map{|l| l.strip}
36
+ result_lines = result.split("\n").map{|l| l.strip}
37
+ expected_lines.zip(result_lines).each{|e, r|
38
+ assert_equal(e, r)
39
+ }
40
+ end
41
+
42
+ def test_code_object_method
43
+
44
+ end
45
+
46
+ def test_docstring_method
47
+
48
+ end
49
+
50
+ def test_docstring_tags_method
51
+
52
+ end
53
+
54
+ def test_signature_method
55
+
56
+ end
57
+
58
+ def test_parameter_defaults_method
59
+
60
+ end
61
+
62
+ def test_visibility_method
63
+
64
+ end
65
+
66
+ def test_scope_method
67
+
68
+ end
69
+
70
+ def test_commented_source_unbound
71
+
72
+ end
73
+
74
+ def test_code_object_unbound
75
+
76
+ end
77
+
78
+ def test_docstring_unbound
79
+
80
+ end
81
+
82
+ def test_docstring_tags_unbound
83
+
84
+ end
85
+
86
+ def test_signature_unbound
87
+
88
+ end
89
+
90
+ def test_parameter_defaults_unbound
91
+
92
+ end
93
+
94
+ def test_visibility_unbound
95
+
96
+ end
97
+
98
+ def test_scope_unbound
99
+
100
+ end
101
+
102
+ def test_commented_source_proc
103
+
104
+ end
105
+
106
+ def test_code_object_proc
107
+
108
+ end
109
+
110
+ def test_docstring_proc
111
+
112
+ end
113
+
114
+ def test_docstring_tags_proc
115
+
116
+ end
117
+
118
+ def test_signature_proc
119
+
120
+ end
121
+
122
+ def test_parameter_defaults_proc
123
+
124
+ end
125
+
126
+ def test_visibility_proc
127
+
128
+ end
129
+
130
+ def test_scope_proc
131
+
132
+ end
133
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: method_reflect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny Purcell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: method_source
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.7.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.7.6
83
+ description: Adds several instance methods to the core Method class so methods can
84
+ tell you more about themselves.
85
+ email:
86
+ - d.purcell.jr+method_reflect@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/method_reflect.rb
97
+ - lib/method_reflect/version.rb
98
+ - method_reflect.gemspec
99
+ - test/method_reflect_test.rb
100
+ homepage: http://dannypurcell.github.io/method_reflect
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.3
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Gives Ruby Methods some deeper self-knowledge
124
+ test_files:
125
+ - test/method_reflect_test.rb
126
+ has_rdoc: