activerecord-archiver 0.1.4 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/activerecord-archiver/archiver.rb +22 -5
- data/lib/activerecord-archiver/export.rb +6 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bdff8e8f67863ac5b05cfa5e3daa7840b75a8dc
|
4
|
+
data.tar.gz: 710d3165f5fdc54c300c821218194049e17832cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c86715f1d5e18e6f10db8b77404bde002a7b5c87b64c8011d4c7665725063877e048f670cd8a1550e0e854029704465e2d2af2bd1254e08b58e83efab9972f08
|
7
|
+
data.tar.gz: 3e83f5603dbba48fe6049e4bcd30cc3656ce03a6fb8ad51c53896929c3a7ef9eae2cf334b8bdfb90ad8258fe51d1d228c2b989ca83e97796bd8124906f610632
|
@@ -81,18 +81,35 @@ class ActiveRecordArchiver
|
|
81
81
|
model.reflections.values.detect{|ref| ref.foreign_key == attribute}
|
82
82
|
end
|
83
83
|
|
84
|
-
def self.
|
84
|
+
def self.parse_array_option options, key
|
85
|
+
if options.is_a? Hash
|
86
|
+
case options[key]
|
87
|
+
when Array then options[key].map(&:to_s)
|
88
|
+
when nil then []
|
89
|
+
else [options[key].to_s] end
|
90
|
+
else [] end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.id_warning model, col
|
94
|
+
"Warning: #{model}##{col.name} included in export." +
|
95
|
+
" To exclude it use ActiveRecordArchiver.export(#{model.name.downcase.pluralize} => " +
|
96
|
+
"{:exclude => [:#{col.name}]})"
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.cols_for_model model, all_models, options={}
|
85
100
|
model.columns.map do |col|
|
86
|
-
if col.primary
|
87
|
-
|
101
|
+
if (col.primary or
|
102
|
+
parse_array_option(options, :exclude).include? col.name)
|
103
|
+
# omit primary keys and excluded columns
|
88
104
|
nil
|
89
|
-
elsif (relation = relation_from_key(model, col.name))
|
105
|
+
elsif (relation = relation_from_key(model, col.name)) and relation.belongs_to?
|
90
106
|
# include belongs_to relations to included models
|
91
107
|
if all_models.include? relation.klass
|
92
108
|
relation.name
|
93
109
|
else nil end
|
94
110
|
else
|
95
|
-
warn
|
111
|
+
# warn before adding an attribute ending in '_id'
|
112
|
+
warn id_warning(model, col) if col.name =~ /_id$/
|
96
113
|
col.name
|
97
114
|
end
|
98
115
|
end.compact
|
@@ -104,9 +104,12 @@ class ActiveRecordArchiver
|
|
104
104
|
options.each_pair do |collection, cols|
|
105
105
|
models_hash[collection.first.class] =
|
106
106
|
[collection,
|
107
|
-
if cols
|
108
|
-
|
109
|
-
|
107
|
+
if cols.is_a? Array then cols
|
108
|
+
elsif cols == :all or cols.is_a? Hash
|
109
|
+
cols_for_model(collection.first.class, models, cols)
|
110
|
+
else
|
111
|
+
raise "unknown column specification: #{cols}"
|
112
|
+
end]
|
110
113
|
end
|
111
114
|
|
112
115
|
models_hash
|