caller_class 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: 0efaed4ffd404f1ed60a9926b3c742550a4cea4f
4
+ data.tar.gz: 554af10a9f9a34fb7bf9bc473a672cbed98c2a90
5
+ SHA512:
6
+ metadata.gz: 58e3e4d6e8f4cb7f4a42abc12a2c1afa4eaea7d8316f30badda05208bafe31f10656c31862f3802e912fafa81682fdddfac4734bed2585fd3af00cc81c45718d
7
+ data.tar.gz: 2dc4722fb8ce41c6514aebde587d8ee67b350f0dbae077eaeb1134a5c1921277c241f78faf23e248a746daf9de8bc65b1346c34f28a16f8036645a009a4460e6
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /doc/
4
+ /pkg/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 kami
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,74 @@
1
+ # CallerClass
2
+
3
+ CallerClass provides the way that to get caller class name that is calling from the body of a class definition.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'caller_class'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install caller_class
20
+
21
+ ## Usage
22
+
23
+ Extend CallerClass module and call `caller_class`.
24
+ This method returns a class name calling the method.
25
+
26
+ ## Example
27
+
28
+ Call from the body of a class definition:
29
+
30
+ ```ruby
31
+ class Foo
32
+ extend CallerClass
33
+
34
+ p caller_class #=> "Foo"
35
+ end
36
+ ```
37
+
38
+ Call from the body of a nested class definition:
39
+
40
+ ```ruby
41
+ class Foo
42
+ class Bar
43
+ extend CallerClass
44
+
45
+ caller_class #=> "Bar"
46
+ end
47
+ end
48
+ ```
49
+
50
+ Call from extended class:
51
+
52
+ ```ruby
53
+ module Foo
54
+ include CallerClass
55
+
56
+ def foo
57
+ p caller_class #=> "Bar"
58
+ end
59
+ end
60
+
61
+ class Bar
62
+ extend Foo
63
+
64
+ foo
65
+ end
66
+ ```
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( https://github.com/kami30k/caller_class/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'caller_class/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'caller_class'
9
+ spec.version = CallerClass::VERSION
10
+ spec.authors = ['kami']
11
+ spec.email = ['kami30k@gmail.com']
12
+ spec.summary = %q{Get caller class name that is calling from the body of a class definition.}
13
+ spec.description = %q{Get caller class name that is calling from the body of a class definition.}
14
+ spec.homepage = 'https://github.com/kami30k/caller_class'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec'
25
+ end
@@ -0,0 +1,10 @@
1
+ require 'caller_class/version'
2
+
3
+ module CallerClass
4
+ PATTERN = /\<class\:(\w+)\>/
5
+
6
+ def caller_class
7
+ klass = caller.detect { |c| c =~ PATTERN }
8
+ klass.match(PATTERN)[1] if klass
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module CallerClass
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe CallerClass do
4
+ context 'call from the body of a class definition' do
5
+ let(:a) do
6
+ class A
7
+ extend CallerClass
8
+
9
+ caller_class
10
+ end
11
+ end
12
+
13
+ it { expect(a).to eq('A') }
14
+ end
15
+
16
+ context 'call from the body of a nested class definition' do
17
+ let(:b) do
18
+ class B
19
+ class BB
20
+ extend CallerClass
21
+
22
+ caller_class
23
+ end
24
+ end
25
+ end
26
+
27
+ it { expect(b).to eq('BB') }
28
+ end
29
+
30
+ context 'call from extended class' do
31
+ let(:c) do
32
+ module C
33
+ include CallerClass
34
+
35
+ def c
36
+ caller_class
37
+ end
38
+ end
39
+
40
+ class CC
41
+ extend C
42
+
43
+ c
44
+ end
45
+ end
46
+
47
+ it { expect(c).to eq('CC') }
48
+ end
49
+
50
+ context 'call from module' do
51
+ let(:d) do
52
+ module D
53
+ extend CallerClass
54
+
55
+ caller_class
56
+ end
57
+ end
58
+
59
+ it { expect(d).to be_nil }
60
+ end
61
+ end
@@ -0,0 +1 @@
1
+ require 'caller_class'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caller_class
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-20 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: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ description: Get caller class name that is calling from the body of a class definition.
56
+ email:
57
+ - kami30k@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - caller_class.gemspec
69
+ - lib/caller_class.rb
70
+ - lib/caller_class/version.rb
71
+ - spec/caller_class_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/kami30k/caller_class
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Get caller class name that is calling from the body of a class definition.
97
+ test_files:
98
+ - spec/caller_class_spec.rb
99
+ - spec/spec_helper.rb