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.
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ - "2.0.0"
7
+ - jruby-18mode # JRuby in 1.8 mode
8
+ - jruby-19mode # JRuby in 1.9 mode
9
+ - rbx-18mode
10
+ - rbx-19mode
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 "jeweler", "~> 1.8.4"
13
- gem "simplecov", require: false
11
+ gem 'rake'
12
+ unless ENV['TRAVIS']
13
+ gem "rdoc", "~> 3.12"
14
+ gem "jeweler", "~> 1.8.4"
15
+ end
14
16
  end
@@ -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
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "lazy_const"
18
- gem.homepage = "http://github.com/rmg/lazy_const"
19
- gem.license = "MIT"
20
- gem.summary = %Q{A little Ruby gem for defining lazy evaluated constants.}
21
- gem.description = %Q{Allows you to define lazy evaluated, constant-like instances of your class.}
22
- gem.email = "r.m.graham@gmail.com"
23
- gem.authors = ["Ryan Graham"]
24
- # dependencies defined in Gemfile
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.2
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lazy_const"
8
- s.version = "0.1.2"
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-13"
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
 
@@ -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
- define_singleton_method name do
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.constantize.public_send name.to_sym
21
+ m = const_get(klass.to_sym).send name.to_sym
18
22
  end
19
23
  end
20
24
 
@@ -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
- assert_equal Foo.TEST, 42
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
- assert_equal Foo.TEST, 42
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.2
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-13 00:00:00.000000000 Z
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: '3.12'
36
+ version: '0'
37
37
  type: :development
38
- name: rdoc
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: '3.12'
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: bundler
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: 1.8.4
68
+ version: '3.12'
69
69
  type: :development
70
- name: jeweler
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: 1.8.4
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: '0'
84
+ version: 1.8.4
85
85
  type: :development
86
- name: simplecov
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: '0'
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: 982838098353150692
129
+ hash: 3223332146885681198
129
130
  version: '0'
130
131
  required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  none: false