named_instances 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/named_instances.rb +2 -2
- data/lib/named_instances/version.rb +3 -0
- data/lib/rails/named_instances.rb +7 -0
- metadata +35 -62
- data/.document +0 -5
- data/.gitignore +0 -6
- data/README.rdoc +0 -20
- data/Rakefile +0 -58
- data/VERSION +0 -1
- data/named_instances.gemspec +0 -65
- data/rails/init.rb +0 -1
- data/test/fixtures/diagnosis.rb +0 -19
- data/test/named_instances_test.rb +0 -70
- data/test/rails_crutch.rb +0 -12
- data/test/test_helper.rb +0 -15
data/lib/named_instances.rb
CHANGED
@@ -12,8 +12,8 @@ module NamedInstances
|
|
12
12
|
@find_options = options[:find_options]
|
13
13
|
|
14
14
|
after_save do
|
15
|
-
Rails.logger.info("Reloading #{self} named instances because of a save")
|
16
|
-
self.load_named_instances
|
15
|
+
Rails.logger.info("Reloading #{self.class} named instances because of a save")
|
16
|
+
self.class.load_named_instances
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: named_instances
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Jason Dew
|
@@ -9,92 +15,59 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-10-14 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: thoughtbot-shoulda
|
17
|
-
type: :development
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: mocha
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "0"
|
34
|
-
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: activesupport
|
37
|
-
type: :development
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: "0"
|
44
|
-
version:
|
20
|
+
dependencies: []
|
21
|
+
|
45
22
|
description: Give cached access to ActiveRecord models for quicker and more readable data-based logic.
|
46
|
-
email:
|
23
|
+
email:
|
24
|
+
- jason.dew@gmail.com
|
47
25
|
executables: []
|
48
26
|
|
49
27
|
extensions: []
|
50
28
|
|
51
|
-
extra_rdoc_files:
|
52
|
-
|
53
|
-
- README.rdoc
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
54
31
|
files:
|
55
|
-
- .
|
56
|
-
- .gitignore
|
57
|
-
- LICENSE
|
58
|
-
- README.rdoc
|
59
|
-
- Rakefile
|
60
|
-
- VERSION
|
32
|
+
- lib/named_instances/version.rb
|
61
33
|
- lib/named_instances.rb
|
62
|
-
- named_instances.
|
63
|
-
-
|
64
|
-
- test/fixtures/diagnosis.rb
|
65
|
-
- test/named_instances_test.rb
|
66
|
-
- test/rails_crutch.rb
|
67
|
-
- test/test_helper.rb
|
34
|
+
- lib/rails/named_instances.rb
|
35
|
+
- LICENSE
|
68
36
|
has_rdoc: true
|
69
37
|
homepage: http://github.com/jasondew/named_instances
|
70
38
|
licenses: []
|
71
39
|
|
72
40
|
post_install_message:
|
73
|
-
rdoc_options:
|
74
|
-
|
41
|
+
rdoc_options: []
|
42
|
+
|
75
43
|
require_paths:
|
76
44
|
- lib
|
77
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
78
47
|
requirements:
|
79
48
|
- - ">="
|
80
49
|
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
81
53
|
version: "0"
|
82
|
-
version:
|
83
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
84
56
|
requirements:
|
85
57
|
- - ">="
|
86
58
|
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
59
|
+
hash: 23
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 3
|
63
|
+
- 6
|
64
|
+
version: 1.3.6
|
89
65
|
requirements: []
|
90
66
|
|
91
|
-
rubyforge_project:
|
92
|
-
rubygems_version: 1.3.
|
67
|
+
rubyforge_project: named_instances
|
68
|
+
rubygems_version: 1.3.7
|
93
69
|
signing_key:
|
94
70
|
specification_version: 3
|
95
|
-
summary:
|
96
|
-
test_files:
|
97
|
-
|
98
|
-
- test/named_instances_test.rb
|
99
|
-
- test/rails_crutch.rb
|
100
|
-
- test/test_helper.rb
|
71
|
+
summary: Model.get(:name)
|
72
|
+
test_files: []
|
73
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/README.rdoc
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
= Named Instances
|
2
|
-
|
3
|
-
Provides support for named instances in Rails.
|
4
|
-
|
5
|
-
Quick usage:
|
6
|
-
|
7
|
-
class Diagnosis < ActiveRecord::Base
|
8
|
-
has_named_instances :name
|
9
|
-
end
|
10
|
-
|
11
|
-
Diagnosis.create :name => "Diabetes Mellitus"
|
12
|
-
|
13
|
-
>> Diagnosis.get(:diabetes_mellitus)
|
14
|
-
=> #<Diagnosis id: 52, name: "Diabetes Mellitus", created_at: "2009-10-07 15:41:50", updated_at: "2009-10-07 15:41:50">
|
15
|
-
|
16
|
-
Patches welcome, enjoy!
|
17
|
-
|
18
|
-
== Copyright
|
19
|
-
|
20
|
-
Copyright (c) 2009 Jason Dew. See LICENSE for details.
|
data/Rakefile
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "named_instances"
|
8
|
-
gem.summary = %Q{Named instances for ActiveRecord}
|
9
|
-
gem.description = %Q{Give cached access to ActiveRecord models for quicker and more readable data-based logic.}
|
10
|
-
gem.email = "jason.dew@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/jasondew/named_instances"
|
12
|
-
gem.authors = ["Jason Dew"]
|
13
|
-
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
-
gem.add_development_dependency "mocha"
|
15
|
-
gem.add_development_dependency "activesupport"
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
-
end
|
21
|
-
|
22
|
-
require 'rake/testtask'
|
23
|
-
Rake::TestTask.new(:test) do |test|
|
24
|
-
test.libs << 'lib' << 'test'
|
25
|
-
test.pattern = 'test/**/*_test.rb'
|
26
|
-
test.verbose = true
|
27
|
-
end
|
28
|
-
|
29
|
-
begin
|
30
|
-
require 'rcov/rcovtask'
|
31
|
-
Rcov::RcovTask.new do |test|
|
32
|
-
test.libs << 'test'
|
33
|
-
test.pattern = 'test/**/*_test.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
rescue LoadError
|
37
|
-
task :rcov do
|
38
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
task :test => :check_dependencies
|
43
|
-
|
44
|
-
task :default => :test
|
45
|
-
|
46
|
-
require 'rake/rdoctask'
|
47
|
-
Rake::RDocTask.new do |rdoc|
|
48
|
-
if File.exist?('VERSION')
|
49
|
-
version = File.read('VERSION')
|
50
|
-
else
|
51
|
-
version = ""
|
52
|
-
end
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "named_instances #{version}"
|
56
|
-
rdoc.rdoc_files.include('README*')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.3
|
data/named_instances.gemspec
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{named_instances}
|
8
|
-
s.version = "0.0.3"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jason Dew"]
|
12
|
-
s.date = %q{2009-12-11}
|
13
|
-
s.description = %q{Give cached access to ActiveRecord models for quicker and more readable data-based logic.}
|
14
|
-
s.email = %q{jason.dew@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/named_instances.rb",
|
27
|
-
"named_instances.gemspec",
|
28
|
-
"rails/init.rb",
|
29
|
-
"test/fixtures/diagnosis.rb",
|
30
|
-
"test/named_instances_test.rb",
|
31
|
-
"test/rails_crutch.rb",
|
32
|
-
"test/test_helper.rb"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/jasondew/named_instances}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.5}
|
38
|
-
s.summary = %q{Named instances for ActiveRecord}
|
39
|
-
s.test_files = [
|
40
|
-
"test/fixtures/diagnosis.rb",
|
41
|
-
"test/named_instances_test.rb",
|
42
|
-
"test/rails_crutch.rb",
|
43
|
-
"test/test_helper.rb"
|
44
|
-
]
|
45
|
-
|
46
|
-
if s.respond_to? :specification_version then
|
47
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
-
s.specification_version = 3
|
49
|
-
|
50
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
53
|
-
s.add_development_dependency(%q<activesupport>, [">= 0"])
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
56
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
57
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
58
|
-
end
|
59
|
-
else
|
60
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
61
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
62
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ActiveRecord::Base.send(:include, NamedInstances)
|
data/test/fixtures/diagnosis.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'active_record'
|
3
|
-
|
4
|
-
class Diagnosis < ActiveRecord::Base
|
5
|
-
include NamedInstances
|
6
|
-
has_named_instances :name
|
7
|
-
end
|
8
|
-
|
9
|
-
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'test/test.db'
|
10
|
-
|
11
|
-
ActiveRecord::Schema.define do
|
12
|
-
create_table :diagnoses, :force => true do |t|
|
13
|
-
t.string :name
|
14
|
-
t.timestamps
|
15
|
-
end
|
16
|
-
|
17
|
-
Diagnosis.create :name => "Hypertension"
|
18
|
-
Diagnosis.create :name => "Diabetes Mellitus"
|
19
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class NamedInstancesTest < Test::Unit::TestCase
|
4
|
-
context "Named instances of an AR model" do
|
5
|
-
|
6
|
-
should "be able get instances" do
|
7
|
-
result = Diagnosis.get(:diabetes_mellitus)
|
8
|
-
assert_equal Diagnosis.find_by_name("Diabetes Mellitus"), result
|
9
|
-
end
|
10
|
-
|
11
|
-
should "reload after a save" do
|
12
|
-
Diagnosis.get(:diabetes_mellitus)
|
13
|
-
new_behavior = Diagnosis.create(:name=>"test1")
|
14
|
-
|
15
|
-
result = Diagnosis.get(:test1)
|
16
|
-
assert_equal new_behavior, result
|
17
|
-
end
|
18
|
-
|
19
|
-
should "raise an error if it doesn't exist at all" do
|
20
|
-
assert_raise ArgumentError do
|
21
|
-
Diagnosis.get(:test2)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
should "find deleted instances as well" do
|
26
|
-
Diagnosis.get(:diabetes_mellitus).destroy
|
27
|
-
Diagnosis.load_named_instances
|
28
|
-
|
29
|
-
assert Diagnosis.get(:diabetes_mellitus)
|
30
|
-
end
|
31
|
-
|
32
|
-
should "maintain the same class object id on get" do
|
33
|
-
result = Diagnosis.get(:diabetes_mellitus)
|
34
|
-
assert_equal Diagnosis.object_id, result.class.object_id
|
35
|
-
end
|
36
|
-
|
37
|
-
should "return the method used for naming" do
|
38
|
-
assert_equal(:name, Diagnosis.name_method)
|
39
|
-
end
|
40
|
-
|
41
|
-
should "accept an array of naming methods" do
|
42
|
-
Foo = Struct.new(:bar, :baz)
|
43
|
-
Foo.send(:include, NamedInstances)
|
44
|
-
|
45
|
-
foo1 = Foo.new("abc", "def")
|
46
|
-
foo2 = Foo.new("xyz", "zzz")
|
47
|
-
|
48
|
-
Foo.expects(:after_save)
|
49
|
-
Foo.expects(:all).returns([foo1, foo2])
|
50
|
-
|
51
|
-
Rails.cache.expects(:write).with("named_instances_NamedInstancesTest::Foo_abc_def", foo1)
|
52
|
-
Rails.cache.expects(:write).with("named_instances_NamedInstancesTest::Foo_xyz_zzz", foo2)
|
53
|
-
|
54
|
-
Foo.has_named_instances [:bar, :baz]
|
55
|
-
assert Foo.load_named_instances
|
56
|
-
end
|
57
|
-
|
58
|
-
should "not crash if the instances can't be loaded immediately" do
|
59
|
-
BadFoo = Struct.new(:bar, :baz)
|
60
|
-
BadFoo.send(:include, NamedInstances)
|
61
|
-
|
62
|
-
BadFoo.expects(:after_save)
|
63
|
-
BadFoo.expects(:all).raises(Exception)
|
64
|
-
|
65
|
-
BadFoo.has_named_instances [:bar, :baz]
|
66
|
-
assert_match /exception/, BadFoo.load_named_instances
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
data/test/rails_crutch.rb
DELETED
data/test/test_helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'shoulda'
|
4
|
-
require 'mocha'
|
5
|
-
require 'rails_crutch'
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'fixtures'))
|
9
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
-
|
11
|
-
require 'named_instances'
|
12
|
-
require 'diagnosis'
|
13
|
-
|
14
|
-
class Test::Unit::TestCase
|
15
|
-
end
|