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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97c0abdbfd631c850f338c67a44603dd0cce276b
4
- data.tar.gz: d1cc6d9d1252274fa5116f023dc33155fcbb3bc5
3
+ metadata.gz: 2bdff8e8f67863ac5b05cfa5e3daa7840b75a8dc
4
+ data.tar.gz: 710d3165f5fdc54c300c821218194049e17832cb
5
5
  SHA512:
6
- metadata.gz: 9f77bb6d5eae62249dec8de855acc796af1ec13b9834d0201d809413a0d8519242395db71dd5daf131315fb1501bfe8cd29b7e998419b1d20df9e7031144ec1f
7
- data.tar.gz: 827510f31bbf47b063124136b6588232b7519b2734ed19bb604f4bfa87c29ba5797885e6b48c1aec2da7ee7c62c2b4e9a40b3b08f22c427baa4354a331697043
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.cols_for_model model, all_models
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
- # omit primary keys
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 "Warning: #{model}##{col.name} included in export" if col.name =~ /_id$/
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 == :all
108
- cols_for_model(collection.first.class, models)
109
- else cols end]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-archiver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Auciello