handy_const 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +6 -0
- data/handy_const.gemspec +24 -0
- data/lib/handy_const/version.rb +3 -0
- data/lib/handy_const.rb +21 -0
- data/spec/handy_const_spec.rb +47 -0
- data/spec/spec_helper.rb +1 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4c38cdbbc74e78d80ef7760bba0ac9097b0ceb3
|
4
|
+
data.tar.gz: f91b432735eee91f37a2159ab6f19192a3a1256a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a01ee4f9f56a8ab882b73d2039b657db635cf098047cb49eaa6f466ace30516dcaf89ab3e1b11169f13ce9c42c2b7b9340d547be9cc0d17a9bb96dd978a7c3ab
|
7
|
+
data.tar.gz: 33d24c2c14f36487c32a9db0e0212d831c1fab0f85ed40b1580b534f2736272df02266d3dcdae40cd48953512a0d7c60ace0e1dad01b860a13fef4154bf16352
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alexey Volodkin
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# HandyConst
|
2
|
+
|
3
|
+
Easy class and instance methods definition for consts access. And no more freeze!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add to Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'handy_const'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Include HandyConst in your class and define some constants
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
class Foo
|
19
|
+
include HandyConst
|
20
|
+
|
21
|
+
const :foo, 'foo'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Const
|
25
|
+
Foo::FOO
|
26
|
+
=> "foo"
|
27
|
+
|
28
|
+
# Class method
|
29
|
+
Foo.foo
|
30
|
+
=> "foo"
|
31
|
+
|
32
|
+
# Instance method
|
33
|
+
Foo.new.foo
|
34
|
+
=> "foo"
|
35
|
+
|
36
|
+
# Frozen for you!
|
37
|
+
Foo.foo.frozen?
|
38
|
+
=> true
|
39
|
+
```
|
40
|
+
|
41
|
+
Call `HandyConst.extend_module!` if you want to make available `const` method in any class and module
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
HandyConst.extend_module!
|
45
|
+
|
46
|
+
class Bar
|
47
|
+
const :bar, 'bar'
|
48
|
+
end
|
49
|
+
|
50
|
+
Bar::BAR
|
51
|
+
# => "bar"
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/handy_const.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'handy_const/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'handy_const'
|
7
|
+
spec.version = HandyConst::VERSION
|
8
|
+
spec.authors = ['Alexey Volodkin']
|
9
|
+
spec.email = ['a@vldkn.net']
|
10
|
+
spec.description = %q{Define class and instance methods for consts access}
|
11
|
+
spec.summary = %q{Handy const definition}
|
12
|
+
spec.homepage = 'https://github.com/miraks/handy_const'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec', '3.0.0.beta2'
|
23
|
+
spec.add_development_dependency 'guard-rspec'
|
24
|
+
end
|
data/lib/handy_const.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'handy_const/version'
|
2
|
+
|
3
|
+
module HandyConst
|
4
|
+
def self.extend_module!
|
5
|
+
Module.send :include, self
|
6
|
+
end
|
7
|
+
|
8
|
+
def const name, value
|
9
|
+
const_name = name.to_s.upcase
|
10
|
+
const_set const_name, value.freeze
|
11
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
12
|
+
def self.#{name}
|
13
|
+
#{const_name}
|
14
|
+
end
|
15
|
+
|
16
|
+
def #{name}
|
17
|
+
#{const_name}
|
18
|
+
end
|
19
|
+
CODE
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HandyConst do
|
4
|
+
let(:klass) { Class.new }
|
5
|
+
|
6
|
+
subject { klass }
|
7
|
+
|
8
|
+
describe "#const" do
|
9
|
+
before :each do
|
10
|
+
klass.extend HandyConst
|
11
|
+
@foo = 'foo'
|
12
|
+
klass.const :foo, @foo
|
13
|
+
end
|
14
|
+
|
15
|
+
it "freeze passed value" do
|
16
|
+
expect(@foo).to be_frozen
|
17
|
+
end
|
18
|
+
|
19
|
+
it "defines const" do
|
20
|
+
expect(klass::FOO).to eq @foo
|
21
|
+
end
|
22
|
+
|
23
|
+
it "defines class method" do
|
24
|
+
expect(klass.foo).to eq @foo
|
25
|
+
end
|
26
|
+
|
27
|
+
it "defines instance method" do
|
28
|
+
expect(klass.new.foo).to eq @foo
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "Module not extended" do
|
33
|
+
it "not available in any class" do
|
34
|
+
should_not respond_to :const
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "Module extended" do
|
39
|
+
before :all do
|
40
|
+
HandyConst.extend_module!
|
41
|
+
end
|
42
|
+
|
43
|
+
it "available in any class" do
|
44
|
+
should respond_to :const
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'handy_const'
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: handy_const
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexey Volodkin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-21 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: rake
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0.beta2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0.beta2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Define class and instance methods for consts access
|
70
|
+
email:
|
71
|
+
- a@vldkn.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- Guardfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- handy_const.gemspec
|
84
|
+
- lib/handy_const.rb
|
85
|
+
- lib/handy_const/version.rb
|
86
|
+
- spec/handy_const_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/miraks/handy_const
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Handy const definition
|
112
|
+
test_files:
|
113
|
+
- spec/handy_const_spec.rb
|
114
|
+
- spec/spec_helper.rb
|