lazy_const 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -0
- data/VERSION +1 -1
- data/lazy_const.gemspec +62 -0
- data/lib/lazy_const.rb +2 -2
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -8,6 +8,8 @@ A simple way of defining lazy evaluated, const-like instances of a class.
|
|
8
8
|
|
9
9
|
== Example
|
10
10
|
|
11
|
+
=== Basic Usage
|
12
|
+
|
11
13
|
class Group
|
12
14
|
extend LazyConst
|
13
15
|
lazy_const :EVERYONE do
|
@@ -32,6 +34,24 @@ A simple way of defining lazy evaluated, const-like instances of a class.
|
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
37
|
+
=== Testing with RSpec
|
38
|
+
|
39
|
+
spec/spec_helper.rb:
|
40
|
+
require 'lazy_const/spec'
|
41
|
+
|
42
|
+
lib/some_class.rb:
|
43
|
+
class SomeClass
|
44
|
+
extend LazyConst
|
45
|
+
lazy_const :IMPORTANT_INSTACE do
|
46
|
+
new(:hotness)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
spec/some_spec.rb:
|
51
|
+
describe MyClass do
|
52
|
+
defines_const :IMPORTANT_INSTANCE
|
53
|
+
# ...
|
54
|
+
end
|
35
55
|
|
36
56
|
== Contributing to lazy_const
|
37
57
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lazy_const.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "lazy_const"
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Graham"]
|
12
|
+
s.date = "2013-03-13"
|
13
|
+
s.description = "Allows you to define lazy evaluated, constant-like instances of your class."
|
14
|
+
s.email = "r.m.graham@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lazy_const.gemspec",
|
27
|
+
"lib/lazy_const.rb",
|
28
|
+
"lib/lazy_const/spec.rb",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/test_lazy_const.rb"
|
31
|
+
]
|
32
|
+
s.homepage = "http://github.com/rmg/lazy_const"
|
33
|
+
s.licenses = ["MIT"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = "1.8.23"
|
36
|
+
s.summary = "A little Ruby gem for defining lazy evaluated constants."
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
43
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
44
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
46
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
50
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
51
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
52
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/lazy_const.rb
CHANGED
@@ -4,7 +4,7 @@ module LazyConst
|
|
4
4
|
|
5
5
|
def lazy_const(name, &block)
|
6
6
|
raise Error("lazy_const requires a block") unless block_given?
|
7
|
-
LazyConst::CACHE
|
7
|
+
LazyConst::CACHE["#{self.name}.#{name}"] = nil
|
8
8
|
define_singleton_method name do
|
9
9
|
LazyConst::CACHE["#{self.name}.#{name}"] ||= block.call
|
10
10
|
end
|
@@ -14,7 +14,7 @@ module LazyConst
|
|
14
14
|
self.clear
|
15
15
|
LazyConst::CACHE.keys.each do |class_dot_name|
|
16
16
|
klass, name = class_dot_name.split('.')
|
17
|
-
m = klass.constantize.
|
17
|
+
m = klass.constantize.public_send name.to_sym
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: lazy_const
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Graham
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- README.rdoc
|
107
107
|
- Rakefile
|
108
108
|
- VERSION
|
109
|
+
- lazy_const.gemspec
|
109
110
|
- lib/lazy_const.rb
|
110
111
|
- lib/lazy_const/spec.rb
|
111
112
|
- test/helper.rb
|
@@ -124,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
125
|
- !ruby/object:Gem::Version
|
125
126
|
segments:
|
126
127
|
- 0
|
127
|
-
hash:
|
128
|
+
hash: 982838098353150692
|
128
129
|
version: '0'
|
129
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
131
|
none: false
|