db_reference 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -35,7 +35,7 @@ PKG_FILES = FileList[
35
35
 
36
36
  spec = Gem::Specification.new do |s|
37
37
  s.name = "db_reference"
38
- s.version = "0.0.4"
38
+ s.version = "0.0.5"
39
39
  s.author = "Cam Fowler"
40
40
  s.email = "cameron.fowler@abletech.co.nz"
41
41
  s.homepage = "http://www.abletech.co.nz/"
@@ -50,6 +50,27 @@ References will be loaded in ascending order, so if an order is desired, prepend
50
50
 
51
51
  Run with:
52
52
  rake reference:load
53
+
54
+ Example
55
+ =======
56
+
57
+ The below example ensures that there are 6 locations existing in the database after running the 'rake reference:load'
58
+
59
+
60
+ # db/schema.rb
61
+ create_table 'locations', :force => true do |t|
62
+ t.string 'name', :null => false
63
+ end
64
+
65
+
66
+ # db/reference/000_locations.rb
67
+ Location.update_or_create :id => 1, :name => 'Wellington City'
68
+ Location.update_or_create :id => 2, :name => 'Lower Hutt'
69
+ Location.update_or_create :id => 3, :name => 'Kapiti Coast'
70
+ Location.update_or_create :id => 4, :name => 'Porirua'
71
+ Location.update_or_create :id => 5, :name => 'Upper Hutt'
72
+ Location.update_or_create :id => 6, :name => 'Wairarapa'
73
+
53
74
  """
54
75
  s.files = PKG_FILES.to_a
55
76
  s.require_path = "lib"
data/lib/db_reference.rb CHANGED
@@ -1,2 +1,2 @@
1
- require 'db_reference/active_record_ext'
2
- require 'db_reference/railtie'
1
+ require 'reference/active_record_ext'
2
+ require 'reference/railtie'
@@ -10,7 +10,7 @@ module DbReference
10
10
  # If it exists, it is updated with the given options.
11
11
  #
12
12
  # Returns the record.
13
- def self.update_or_create(attributes = {})
13
+ def update_or_create(attributes = {})
14
14
  id = attributes.delete(:id)
15
15
  record = find_or_initialize_by_id(id)
16
16
  record.attributes = attributes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_reference
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Cam Fowler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-20 00:00:00 +13:00
18
+ date: 2011-04-08 00:00:00 +12:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -23,7 +23,20 @@ description: "\n\n\
23
23
  Used for creating a predefined set of models, similar to db:seed, but will not repopulate if entries already exist.\n\n\
24
24
  Place references in 'db/reference/'\n\
25
25
  References will be loaded in ascending order, so if an order is desired, prepend 000, 001, 002... etc to the filename.\n\n\
26
- Run with:\n rake reference:load\n "
26
+ Run with:\n rake reference:load\n\n\
27
+ Example\n\
28
+ =======\n\n\
29
+ The below example ensures that there are 6 locations existing in the database after running the 'rake reference:load'\n\n\n\
30
+ # db/schema.rb\n\
31
+ create_table 'locations', :force => true do |t|\n t.string 'name', :null => false\n\
32
+ end\n\n\n\
33
+ # db/reference/000_locations.rb\n\
34
+ Location.update_or_create :id => 1, :name => 'Wellington City'\n\
35
+ Location.update_or_create :id => 2, :name => 'Lower Hutt'\n\
36
+ Location.update_or_create :id => 3, :name => 'Kapiti Coast'\n\
37
+ Location.update_or_create :id => 4, :name => 'Porirua'\n\
38
+ Location.update_or_create :id => 5, :name => 'Upper Hutt'\n\
39
+ Location.update_or_create :id => 6, :name => 'Wairarapa'\n\n "
27
40
  email: cameron.fowler@abletech.co.nz
28
41
  executables: []
29
42