spreadsheet_model 0.4.2 → 0.4.3

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: 02d4fa24c86f08983bccbaf240e6d4a4f11527e5
4
- data.tar.gz: 2b29f375c6aeaee0d5d4ef5101f16b2fb37f6b19
3
+ metadata.gz: d09161b7b5fcffe4de869aac0423e9ac33c9c076
4
+ data.tar.gz: 72c3314f35164008ec9a7262f08acd7f29f1fe8b
5
5
  SHA512:
6
- metadata.gz: b2804ccfc22cee0d723f0104880b15c76103a81f349d762c6246e3d54d641bef64802318a71f4eb19592309e2a790f3537891709a2fd1d3bc7b8b39c08af3029
7
- data.tar.gz: 1dc3f81ab3fcf08308d3d8e3725800145fd43d9ea7109f75e04cedf35e08732200f0d5dca2afdfc722f153c9ed6c6620dc65ddc6d4c7179cca8d6f505316908a
6
+ metadata.gz: 981501879576d9d01b6690c7b0467b6faea43b1ed8d59a86f4bde6d2638dc36b3097a4e36ac79c4a3e173ce33b08a1d000c4b115518650d114bb8fe95e85165e
7
+ data.tar.gz: 5520b8db3c9c8b368b4d3015b4e02c203702f05ba26191d4abc2a64d1779864c3ca71657aec95ef83e8a7639a35d7bc59d525311eab7698f9f4bdde8d759790a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spreadsheet_model (0.4.2)
4
+ spreadsheet_model (0.4.3)
5
5
  activemodel
6
6
  activesupport
7
7
  google_drive
@@ -15,8 +15,7 @@ module SpreadsheetModel
15
15
 
16
16
  def self.attr_accessor(*args)
17
17
  super
18
- @column_names ||= []
19
- @column_names.concat(args.map(&:to_s))
18
+ @accessors = args
20
19
  end
21
20
 
22
21
  def [](name)
@@ -43,11 +42,10 @@ module SpreadsheetModel
43
42
 
44
43
  keys = sheets.each_with_object([]) do |sheet, keys|
45
44
  rows = sheet.rows.dup
46
- header = rows.shift
47
- @column_names ||= header
45
+ @column_names = rows.shift
48
46
 
49
47
  store_hash = rows.each_with_object({}) do |row, store_hash|
50
- row_hash = Hash[*header.zip(row).flatten]
48
+ row_hash = Hash[*@column_names.zip(row).flatten]
51
49
  row_hash = @import_callback.call(row_hash) if @import_callback
52
50
  write_rows = [store_hash[row[0]], row_hash].compact.flatten
53
51
  store_hash[row[0]] = write_rows
@@ -60,8 +58,8 @@ module SpreadsheetModel
60
58
  end
61
59
  keys
62
60
  end
63
- write_cache('__keys', keys)
64
- write_cache('__cached', true)
61
+ write_cache('__spreadsheetmodel_keys', keys)
62
+ write_cache('__spreadsheetmodel_cached', true)
65
63
  end
66
64
 
67
65
  # inspired by:
@@ -72,12 +70,17 @@ module SpreadsheetModel
72
70
  end
73
71
 
74
72
  def self.cached?
75
- !!read_cache('__cached')
73
+ !!read_cache('__spreadsheetmodel_cached')
76
74
  end
77
75
 
78
76
  def self.keys
79
77
  import unless cached?
80
- read_cache('__keys')
78
+ read_cache('__spreadsheetmodel_keys')
79
+ end
80
+
81
+ def self.column_names
82
+ import unless cached?
83
+ @column_names
81
84
  end
82
85
 
83
86
  private
@@ -106,8 +109,8 @@ module SpreadsheetModel
106
109
  # https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/relation/finder_methods.rb#L432
107
110
  def self.find_one(id)
108
111
  rows = read_cache(id)
109
- return nil unless rows
110
112
 
113
+ return nil unless rows
111
114
  row_to_instance(rows[0])
112
115
  end
113
116
 
@@ -154,9 +157,8 @@ module SpreadsheetModel
154
157
 
155
158
  def self.row_to_instance(row)
156
159
  return nil unless row
157
- attributes = row.select { |key, _| @column_names.include?(key.to_s) }
158
-
159
- if attributes['type'].to_s.present?
160
+ attributes = row.select { |key, _| @accessors.try(:include?, key.to_sym) }
161
+ if row['type'].to_s.present?
160
162
  instance = attributes['type'].constantize.new(attributes)
161
163
  else
162
164
  instance = self.new(attributes)
@@ -165,10 +167,5 @@ module SpreadsheetModel
165
167
  instance.instance_variable_set(:@__row, row)
166
168
  instance
167
169
  end
168
-
169
- def self.column_names
170
- import unless cached?
171
- @column_names
172
- end
173
170
  end
174
171
  end
@@ -1,3 +1,3 @@
1
1
  module SpreadsheetModel
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - zucay