db_reference 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +13 -0
- data/Rakefile +54 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/db_reference.rb +2 -0
- data/lib/db_reference/active_record_ext.rb +31 -0
- data/lib/db_reference/railtie.rb +10 -0
- data/lib/tasks/db_reference_tasks.rake +14 -0
- data/test/reference_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +78 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
|
6
|
+
desc 'Default: run unit tests.'
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
desc 'Test the reference plugin.'
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.libs << 'test'
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generate documentation for the reference plugin.'
|
18
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = 'Reference'
|
21
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
22
|
+
rdoc.rdoc_files.include('README')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
PKG_FILES = FileList[
|
28
|
+
'[a-zA-Z]*',
|
29
|
+
'generators/**/*',
|
30
|
+
'lib/**/*',
|
31
|
+
'tasks/**/*',
|
32
|
+
'rails/**/*',
|
33
|
+
'test/**/*'
|
34
|
+
]
|
35
|
+
|
36
|
+
spec = Gem::Specification.new do |s|
|
37
|
+
s.name = "db_reference"
|
38
|
+
s.version = "0.0.1"
|
39
|
+
s.author = "Cam Fowler"
|
40
|
+
s.email = "cameron.fowler@abletech.co.nz"
|
41
|
+
s.homepage = "http://www.abletech.co.nz/"
|
42
|
+
s.platform = Gem::Platform::RUBY
|
43
|
+
s.summary = "Loads files from db/reference/"
|
44
|
+
s.files = PKG_FILES.to_a
|
45
|
+
s.require_path = "lib"
|
46
|
+
s.has_rdoc = false
|
47
|
+
s.extra_rdoc_files = ["README"]
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Turn this plugin into a gem.'
|
51
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
52
|
+
pkg.gem_spec = spec
|
53
|
+
end
|
54
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'reference'
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/db_reference.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module DbReference
|
2
|
+
def self.included(base)
|
3
|
+
base.send :extend, ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# Given a hash of attributes including the ID, look up the record by ID.
|
8
|
+
#
|
9
|
+
# If it does not exist, it is created with the rest of the options.
|
10
|
+
# If it exists, it is updated with the given options.
|
11
|
+
#
|
12
|
+
# Returns the record.
|
13
|
+
def self.update_or_create(attributes = {})
|
14
|
+
id = attributes.delete(:id)
|
15
|
+
record = find_or_initialize_by_id(id)
|
16
|
+
record.attributes = attributes
|
17
|
+
|
18
|
+
begin
|
19
|
+
record.save!
|
20
|
+
rescue
|
21
|
+
puts "Save failed for #{record.class}[#{id}] with attributes #{attributes.inspect}"
|
22
|
+
raise
|
23
|
+
end
|
24
|
+
|
25
|
+
record
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveRecord::Base.send :include, DbReference
|
31
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
namespace :reference do
|
2
|
+
desc "Loads reference data values for the current environment."
|
3
|
+
task :load => :environment do
|
4
|
+
files = Dir[File.join(Rails.root, 'db', 'reference', '*.rb')].sort
|
5
|
+
files += Dir[File.join(Rails.root, 'db', 'reference', Rails.env, '*.rb')].sort
|
6
|
+
|
7
|
+
files.each do |file|
|
8
|
+
puts "Populating reference #{file}"
|
9
|
+
load file
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: db_reference
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Cam Fowler
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-20 00:00:00 +13:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: cameron.fowler@abletech.co.nz
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
files:
|
31
|
+
- init.rb
|
32
|
+
- install.rb
|
33
|
+
- MIT-LICENSE
|
34
|
+
- Rakefile
|
35
|
+
- README
|
36
|
+
- uninstall.rb
|
37
|
+
- lib/db_reference/active_record_ext.rb
|
38
|
+
- lib/db_reference/railtie.rb
|
39
|
+
- lib/db_reference.rb
|
40
|
+
- lib/tasks/db_reference_tasks.rake
|
41
|
+
- test/reference_test.rb
|
42
|
+
- test/test_helper.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://www.abletech.co.nz/
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Loads files from db/reference/
|
77
|
+
test_files: []
|
78
|
+
|