-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
75 lines (47 loc) · 1.99 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
ConstantsInDb (for RoR 2.3.5 and above)
=======================================
This plugin allows you to use some active record model instances as constants, and give a way to
- load and update AR constants at runtime
- manage AR constants through seeds files
Example
=======
To load constants stored in db at runtime, add the following code to your AR models :
class Exemple < ActiveRecord::Base
cache_constants :name
end
where name is a string attribute of the ActiveRecord model Exemple, used as unique key to instanciate the Exemple's constants
To manage your constants thanks to seeds, build up the following subdirectory architecture in the "db" directory :
db
|_ seeds
| |_ common
| | |_ seeds_file_1.yml
| | |_ seeds_file_2.yml
| | |_ ..
| |
| |_ development
| | |_ seeds_file_1.yml
| |
| |_ test
|
|_ seeds.rb
Under the seeds directory, create one directory by environment, and a "common" directory, which is used by default to load seeds
In seeds.rb, you'll then be able to instanciate and save your seeds as follow :
#seeds.rb
seeds = Seeds.new => Load all seeds files found in seeds sub-directories
seeds.load_data => Load all data without overriding the values for data allready stored in db
seeds.save => pass the save method to all data previously loaded
or
seeds = Seeds.new(:only => :seeds_file_1) => only load seeds_file_1.yml
seeds.load_data(:override => true) => override data values with seeds values
seeds.save! => pass the save! method to all data previously loaded
or
seeds = Seeds.new(:except => :seeds_file_1) => don't load seeds_file_1.yml
seeds.load_data(:override => true)
seeds.save!
TODO
====
* restrict options should take class names to fully handle STI models
* write a generator to build default seeds directories architecture
* gemmify the plugin
* rails 3 testing
Copyright (c) 2010 webflows, released under the MIT license