built_in_data 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -35,11 +35,12 @@ There are two methods to load data
35
35
  })
36
36
 
37
37
 
38
- * Create a yaml load file in *db/built_in_data* with the name of the model (ie. national_parks.yml), and load the data with `YourModel.load_built_in_data!` without any arguments.
38
+ * Create a yaml load file in *db/built_in_data* with the name of the model (ie. national_parks.yml), and load the data with <tt>YourModel.load_built_in_data!</tt> without any arguments. The yaml file can contain erb.
39
39
 
40
40
  glacier:
41
41
  name: Glacier National Park
42
+ established: <%= Date.parse('1910-05-11') %>
42
43
 
43
44
  yellowstone:
44
45
  name: Yellowstone National Park
45
-
46
+ established: 1872-03-01
@@ -1,3 +1,3 @@
1
1
  module BuiltInData
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/built_in_data.rb CHANGED
@@ -33,7 +33,7 @@ module BuiltInData
33
33
  end
34
34
 
35
35
  def load_yaml_data
36
- YAML.load_file(Rails.root.join('db', 'built_in_data', "#{table_name}.yml"))
36
+ YAML.load(ERB.new(File.read(Rails.root.join('db', 'built_in_data', "#{table_name}.yml"))).result)
37
37
  end
38
38
 
39
39
  def create_or_update!(key, attributes)
@@ -58,6 +58,10 @@ class BuiltInDataTest < ActiveSupport::TestCase
58
58
  NationalPark.load_built_in_data!
59
59
  end
60
60
  end
61
+
62
+ test "should process erb in yaml file" do
63
+ assert_equal '1910-05-11', NationalPark.send(:load_yaml_data)['glacier']['established'].to_s(:db)
64
+ end
61
65
 
62
66
 
63
67
  #######
@@ -5,5 +5,5 @@ yellowstone:
5
5
 
6
6
  glacier:
7
7
  name: Glacier National Park
8
- established: 1910-05-11
8
+ established: <%= Date.parse('1910-05-11') %>
9
9
  url: 'http://www.nps.gov/glac/index.htm'
Binary file
Binary file
@@ -1,75 +1,149 @@
1
1
  Connecting to database specified by database.yml
2
-  (20.1ms) select sqlite_version(*)
3
-  (147.2ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255))
4
-  (108.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
5
-  (0.1ms) PRAGMA index_list("schema_migrations")
6
-  (91.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2
+ Connecting to database specified by database.yml
3
+  (0.1ms) select sqlite_version(*)
4
+  (14.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
5
+  (0.0ms) PRAGMA index_list("schema_migrations")
6
+  (5.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
7
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
8
+ Migrating to CreateNationalParks (20121024195810)
9
+  (0.0ms) begin transaction
10
+  (0.4ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
11
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20121024195810')
12
+  (1.3ms) commit transaction
13
+  (0.2ms) select sqlite_version(*)
14
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
15
+  (0.0ms) PRAGMA index_list("national_parks")
16
+ Connecting to database specified by database.yml
17
+ Connecting to database specified by database.yml
18
+ Connecting to database specified by database.yml
19
+  (3.5ms) select sqlite_version(*)
20
+  (20.7ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255))
21
+  (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
22
+  (0.0ms) PRAGMA index_list("schema_migrations")
23
+  (1.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
7
24
   (0.1ms) SELECT version FROM "schema_migrations"
8
-  (124.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
9
-  (108.5ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
25
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
26
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
10
27
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
11
28
  Connecting to database specified by database.yml
12
29
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
13
-  (0.2ms) select sqlite_version(*)
14
-  (145.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
15
-  (133.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
16
-  (0.1ms) PRAGMA index_list("schema_migrations")
17
-  (116.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
18
-  (0.1ms) SELECT version FROM "schema_migrations"
19
-  (116.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
20
-  (117.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
30
+  (0.1ms) select sqlite_version(*)
31
+  (1.1ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
32
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
33
+  (0.0ms) PRAGMA index_list("schema_migrations")
34
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
35
+  (0.0ms) SELECT version FROM "schema_migrations"
36
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
37
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
21
38
  Connecting to database specified by database.yml
22
-  (19.0ms) select sqlite_version(*)
23
-  (195.5ms) DROP TABLE "national_parks"
24
-  (116.6ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
39
+  (3.6ms) select sqlite_version(*)
40
+  (1.4ms) DROP TABLE "national_parks"
41
+  (1.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
25
42
   (0.1ms) SELECT version FROM "schema_migrations"
26
43
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
27
44
  Connecting to database specified by database.yml
28
45
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
29
-  (0.3ms) select sqlite_version(*)
30
-  (160.3ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
31
-  (116.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
32
-  (0.1ms) PRAGMA index_list("schema_migrations")
33
-  (108.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
34
-  (0.1ms) SELECT version FROM "schema_migrations"
35
-  (149.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
36
-  (92.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
46
+  (0.1ms) select sqlite_version(*)
47
+  (1.1ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
48
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
49
+  (0.0ms) PRAGMA index_list("schema_migrations")
50
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
51
+  (0.0ms) SELECT version FROM "schema_migrations"
52
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
53
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
37
54
  Connecting to database specified by database.yml
38
-  (18.3ms) select sqlite_version(*)
39
-  (137.1ms) DROP TABLE "national_parks"
40
-  (116.6ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
55
+  (3.7ms) select sqlite_version(*)
56
+  (1.1ms) DROP TABLE "national_parks"
57
+  (1.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
41
58
   (0.1ms) SELECT version FROM "schema_migrations"
42
59
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
43
60
  Connecting to database specified by database.yml
44
61
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
45
-  (0.3ms) select sqlite_version(*)
46
-  (135.2ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
47
-  (116.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
48
-  (0.1ms) PRAGMA index_list("schema_migrations")
49
-  (91.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
50
-  (0.1ms) SELECT version FROM "schema_migrations"
51
-  (83.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
52
-  (118.3ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
62
+  (0.1ms) select sqlite_version(*)
63
+  (1.1ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
64
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
65
+  (0.0ms) PRAGMA index_list("schema_migrations")
66
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
67
+  (0.0ms) SELECT version FROM "schema_migrations"
68
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
69
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
53
70
  Connecting to database specified by database.yml
54
-  (0.1ms) select sqlite_version(*)
55
-  (127.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
56
-  (0.1ms) PRAGMA index_list("schema_migrations")
57
-  (99.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
71
+  (3.6ms) select sqlite_version(*)
72
+  (1.4ms) DROP TABLE "national_parks"
73
+  (1.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
74
+  (0.1ms) SELECT version FROM "schema_migrations"
58
75
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
59
76
  Connecting to database specified by database.yml
60
-  (18.7ms) select sqlite_version(*)
61
-  (152.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255))
62
-  (0.1ms) SELECT version FROM "schema_migrations"
63
-  (117.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
64
-  (116.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
65
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
77
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
78
+  (0.1ms) select sqlite_version(*)
79
+  (1.1ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
80
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
81
+  (0.0ms) PRAGMA index_list("schema_migrations")
82
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
83
+  (0.0ms) SELECT version FROM "schema_migrations"
84
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
85
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
66
86
  Connecting to database specified by database.yml
87
+  (3.6ms) select sqlite_version(*)
88
+  (1.1ms) DROP TABLE "national_parks"
89
+  (1.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
90
+  (0.1ms) SELECT version FROM "schema_migrations"
67
91
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
68
-  (0.2ms) select sqlite_version(*)
69
-  (142.2ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
70
-  (116.4ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
71
-  (0.1ms) PRAGMA index_list("schema_migrations")
72
-  (91.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
92
+ Connecting to database specified by database.yml
93
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
94
+  (0.1ms) select sqlite_version(*)
95
+  (1.1ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
96
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
97
+  (0.0ms) PRAGMA index_list("schema_migrations")
98
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
99
+  (0.0ms) SELECT version FROM "schema_migrations"
100
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
101
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
102
+ Connecting to database specified by database.yml
103
+  (3.6ms) select sqlite_version(*)
104
+  (1.2ms) DROP TABLE "national_parks"
105
+  (1.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
106
+  (0.1ms) SELECT version FROM "schema_migrations"
107
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
108
+ Connecting to database specified by database.yml
109
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
110
+  (0.1ms) select sqlite_version(*)
111
+  (1.2ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
112
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
113
+  (0.0ms) PRAGMA index_list("schema_migrations")
114
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
115
+  (0.0ms) SELECT version FROM "schema_migrations"
116
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
117
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
118
+ Connecting to database specified by database.yml
119
+  (3.6ms) select sqlite_version(*)
120
+  (1.4ms) DROP TABLE "national_parks"
121
+  (1.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
122
+  (0.1ms) SELECT version FROM "schema_migrations"
123
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
124
+ Connecting to database specified by database.yml
125
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
126
+  (0.1ms) select sqlite_version(*)
127
+  (36.9ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
128
+  (31.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
129
+  (0.0ms) PRAGMA index_list("schema_migrations")
130
+  (21.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
73
131
   (0.1ms) SELECT version FROM "schema_migrations"
74
-  (91.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
75
-  (83.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
132
+  (23.5ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
133
+  (31.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')
134
+ Connecting to database specified by database.yml
135
+  (3.6ms) select sqlite_version(*)
136
+  (1.1ms) DROP TABLE "national_parks"
137
+  (1.0ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
138
+  (0.1ms) SELECT version FROM "schema_migrations"
139
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
140
+ Connecting to database specified by database.yml
141
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
142
+  (0.1ms) select sqlite_version(*)
143
+  (1.1ms) CREATE TABLE "national_parks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "established" date, "url" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "built_in_key" varchar(255)) 
144
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
145
+  (0.0ms) PRAGMA index_list("schema_migrations")
146
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
147
+  (0.0ms) SELECT version FROM "schema_migrations"
148
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024201818')
149
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20121024195810')