lazy_const 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +10 -0
- data/Gemfile +5 -3
- data/README.rdoc +12 -0
- data/Rakefile +24 -21
- data/VERSION +1 -1
- data/lazy_const.gemspec +9 -8
- data/lib/lazy_const.rb +6 -2
- data/test/test_lazy_const.rb +17 -4
- metadata +18 -17
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -7,8 +7,10 @@ source "http://rubygems.org"
|
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
9
|
gem "minitest", ">= 0"
|
10
|
-
gem "rdoc", "~> 3.12"
|
11
10
|
gem "bundler"
|
12
|
-
gem
|
13
|
-
|
11
|
+
gem 'rake'
|
12
|
+
unless ENV['TRAVIS']
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "jeweler", "~> 1.8.4"
|
15
|
+
end
|
14
16
|
end
|
data/README.rdoc
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
= lazy_const
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/rmg/feature_definitions.png?branch=master)](http://travis-ci.org/rmg/feature_definitions)
|
4
|
+
|
3
5
|
A simple way of defining lazy evaluated, const-like instances of a class.
|
4
6
|
|
7
|
+
Thanks to Travis-CI, tested on:
|
8
|
+
- "1.8.7"
|
9
|
+
- "1.9.2"
|
10
|
+
- "1.9.3"
|
11
|
+
- "2.0.0"
|
12
|
+
- jruby-18mode # JRuby in 1.8 mode
|
13
|
+
- jruby-19mode # JRuby in 1.9 mode
|
14
|
+
- rbx-18mode
|
15
|
+
- rbx-19mode
|
16
|
+
|
5
17
|
== Installation
|
6
18
|
|
7
19
|
gem 'lazy_const'
|
data/Rakefile
CHANGED
@@ -11,19 +11,31 @@ rescue Bundler::BundlerError => e
|
|
11
11
|
end
|
12
12
|
require 'rake'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
unless ENV['TRAVIS']
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "lazy_const"
|
19
|
+
gem.homepage = "http://github.com/rmg/lazy_const"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{A little Ruby gem for defining lazy evaluated constants.}
|
22
|
+
gem.description = %Q{Allows you to define lazy evaluated, constant-like instances of your class.}
|
23
|
+
gem.email = "r.m.graham@gmail.com"
|
24
|
+
gem.authors = ["Ryan Graham"]
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rdoc/task'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
+
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = "lazy_const #{version}"
|
35
|
+
rdoc.rdoc_files.include('README*')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
25
38
|
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
39
|
|
28
40
|
require 'rake/testtask'
|
29
41
|
Rake::TestTask.new(:test) do |test|
|
@@ -34,12 +46,3 @@ end
|
|
34
46
|
|
35
47
|
task :default => :test
|
36
48
|
|
37
|
-
require 'rdoc/task'
|
38
|
-
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
-
|
41
|
-
rdoc.rdoc_dir = 'rdoc'
|
42
|
-
rdoc.title = "lazy_const #{version}"
|
43
|
-
rdoc.rdoc_files.include('README*')
|
44
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lazy_const.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "lazy_const"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ryan Graham"]
|
12
|
-
s.date = "2013-03-
|
12
|
+
s.date = "2013-03-19"
|
13
13
|
s.description = "Allows you to define lazy evaluated, constant-like instances of your class."
|
14
14
|
s.email = "r.m.graham@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
+
".travis.yml",
|
21
22
|
"Gemfile",
|
22
23
|
"LICENSE.txt",
|
23
24
|
"README.rdoc",
|
@@ -40,23 +41,23 @@ Gem::Specification.new do |s|
|
|
40
41
|
|
41
42
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
43
|
s.add_development_dependency(%q<minitest>, [">= 0"])
|
43
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
44
44
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
45
47
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
46
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
47
48
|
else
|
48
49
|
s.add_dependency(%q<minitest>, [">= 0"])
|
49
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
50
50
|
s.add_dependency(%q<bundler>, [">= 0"])
|
51
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
51
53
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
52
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
53
54
|
end
|
54
55
|
else
|
55
56
|
s.add_dependency(%q<minitest>, [">= 0"])
|
56
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
57
|
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
58
60
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
data/lib/lazy_const.rb
CHANGED
@@ -2,10 +2,14 @@ module LazyConst
|
|
2
2
|
|
3
3
|
CACHE = {}
|
4
4
|
|
5
|
+
def meta_class
|
6
|
+
@meta_class ||= class << self; self end
|
7
|
+
end
|
8
|
+
|
5
9
|
def lazy_const(name, &block)
|
6
10
|
raise Error("lazy_const requires a block") unless block_given?
|
7
11
|
LazyConst::CACHE["#{self.name}.#{name}"] = nil
|
8
|
-
|
12
|
+
meta_class.send(:define_method, name) do
|
9
13
|
LazyConst::CACHE["#{self.name}.#{name}"] ||= block.call
|
10
14
|
end
|
11
15
|
end
|
@@ -14,7 +18,7 @@ module LazyConst
|
|
14
18
|
self.clear
|
15
19
|
LazyConst::CACHE.keys.each do |class_dot_name|
|
16
20
|
klass, name = class_dot_name.split('.')
|
17
|
-
m = klass.
|
21
|
+
m = const_get(klass.to_sym).send name.to_sym
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
data/test/test_lazy_const.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
$called = 0
|
4
3
|
class Foo
|
5
4
|
extend LazyConst
|
6
5
|
lazy_const :TEST do
|
@@ -11,12 +10,26 @@ end
|
|
11
10
|
|
12
11
|
|
13
12
|
class TestLazyConst < MiniTest::Unit::TestCase
|
13
|
+
|
14
|
+
def setup
|
15
|
+
$called = 0
|
16
|
+
LazyConst.clear
|
17
|
+
end
|
18
|
+
|
14
19
|
def test_lazy_const
|
15
|
-
called = 0
|
16
20
|
assert_equal $called, 0
|
17
|
-
|
21
|
+
obj = Foo.TEST
|
22
|
+
assert_equal obj, Foo.TEST
|
23
|
+
assert_equal $called, 1
|
24
|
+
assert_equal obj, Foo.TEST
|
18
25
|
assert_equal $called, 1
|
19
|
-
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_preload
|
29
|
+
assert_equal $called, 0
|
30
|
+
LazyConst.preload
|
20
31
|
assert_equal $called, 1
|
32
|
+
obj = Foo.TEST
|
33
|
+
assert_equal obj, Foo.TEST
|
21
34
|
end
|
22
35
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: lazy_const
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Graham
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,17 +31,17 @@ dependencies:
|
|
31
31
|
version_requirements: !ruby/object:Gem::Requirement
|
32
32
|
none: false
|
33
33
|
requirements:
|
34
|
-
- -
|
34
|
+
- - ! '>='
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '0'
|
37
37
|
type: :development
|
38
|
-
name:
|
38
|
+
name: bundler
|
39
39
|
requirement: !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ! '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
44
|
+
version: '0'
|
45
45
|
prerelease: false
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
type: :development
|
54
|
-
name:
|
54
|
+
name: rake
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|
@@ -65,31 +65,31 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '3.12'
|
69
69
|
type: :development
|
70
|
-
name:
|
70
|
+
name: rdoc
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: '3.12'
|
77
77
|
prerelease: false
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
none: false
|
81
81
|
requirements:
|
82
|
-
- -
|
82
|
+
- - ~>
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
84
|
+
version: 1.8.4
|
85
85
|
type: :development
|
86
|
-
name:
|
86
|
+
name: jeweler
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - ~>
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
92
|
+
version: 1.8.4
|
93
93
|
prerelease: false
|
94
94
|
description: Allows you to define lazy evaluated, constant-like instances of your
|
95
95
|
class.
|
@@ -101,6 +101,7 @@ extra_rdoc_files:
|
|
101
101
|
- README.rdoc
|
102
102
|
files:
|
103
103
|
- .document
|
104
|
+
- .travis.yml
|
104
105
|
- Gemfile
|
105
106
|
- LICENSE.txt
|
106
107
|
- README.rdoc
|
@@ -125,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
126
|
- !ruby/object:Gem::Version
|
126
127
|
segments:
|
127
128
|
- 0
|
128
|
-
hash:
|
129
|
+
hash: 3223332146885681198
|
129
130
|
version: '0'
|
130
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
132
|
none: false
|