sheets_db 0.7.0 → 0.8.0

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: b7e907bf49b4cf4aa2db7e42de08bdb000c6f7aa
4
- data.tar.gz: 5cecdaafb237db9ee78068370db3cd0f160c050d
3
+ metadata.gz: 7d2784033de71d261f7e29a9f819ee2c8b9ebe8d
4
+ data.tar.gz: 4eebf8e4ab589e9a4b343c6f963c96df5148fbcd
5
5
  SHA512:
6
- metadata.gz: 94b4e4ce9fc13adc72136d1a37c24bca8343415587230b840d3158c208b3d96ef05bd7025d5aadef166dc5f369e3124a0f80b5249c2cb6a3d1fad9101915a2c4
7
- data.tar.gz: 365e9d23933c27732a87a0760630c89c12b4d12cd878e49084593d08693a337e595351eb19d6a65a60ed4971f3f8a4c74c0cc081267e1d7efbe066430e7075c3
6
+ metadata.gz: eb21d0eff2870d21c7e73acc0cbdd1a19364ceb205f688df194b14ac7a996698eb50b797bf5226194eebbd54e2bc0ac2d098de7f61f90bb2c849b75fc0c53003
7
+ data.tar.gz: 0df6e44c0dc91bb6b55a3298eb11bb6d21bfe48fdedb69bfad9776a567a001fba237876ca6febc0921a69f07efce25bbd3997007199fbeb0360631017bfcf9a6
@@ -1,3 +1,3 @@
1
1
  module SheetsDB
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -10,8 +10,8 @@ module SheetsDB
10
10
  subclass.instance_variable_set(:@attribute_definitions, @attribute_definitions)
11
11
  end
12
12
 
13
- def attribute(name, type: String, multiple: false, transform: nil, column_name: nil)
14
- register_attribute(name, type: type, multiple: multiple, transform: transform, column_name: column_name || name.to_s, association: false)
13
+ def attribute(name, type: String, multiple: false, transform: nil, column_name: nil, if_column_missing: nil)
14
+ register_attribute(name, type: type, multiple: multiple, transform: transform, column_name: column_name || name.to_s, association: false, if_column_missing: if_column_missing)
15
15
 
16
16
  define_method(name) do
17
17
  begin
@@ -45,17 +45,24 @@ module SheetsDB
45
45
  end
46
46
 
47
47
  def get_definition_and_column(attribute_name)
48
- attribute_definition = attribute_definitions.fetch(attribute_name, {})
48
+ attribute_definition = attribute_definitions.fetch(attribute_name)
49
49
  column_name = attribute_definition.fetch(:column_name, attribute_name.to_s)
50
- raise ColumnNotFoundError, column_name if columns[column_name].nil?
51
50
  [
52
51
  attribute_definition,
53
52
  columns[column_name]
54
53
  ]
55
54
  end
56
55
 
56
+ def value_if_column_missing(attribute_definition)
57
+ unless attribute_definition[:if_column_missing]
58
+ raise ColumnNotFoundError, attribute_definition[:column_name]
59
+ end
60
+ attribute_definition[:if_column_missing].call
61
+ end
62
+
57
63
  def attribute_at_row_position(attribute_name, row_position)
58
64
  attribute_definition, column = get_definition_and_column(attribute_name)
65
+ return value_if_column_missing(attribute_definition) unless column
59
66
  raw_value = read_value_from_google_drive_resource(
60
67
  dimensions: [row_position, column.column_position],
61
68
  attribute_definition: attribute_definition
@@ -79,6 +86,7 @@ module SheetsDB
79
86
  def update_attributes_at_row_position(staged_attributes, row_position:)
80
87
  staged_attributes.each do |attribute_name, value|
81
88
  attribute_definition, column = get_definition_and_column(attribute_name)
89
+ raise ColumnNotFoundError, column unless column
82
90
  assignment_value = attribute_definition[:multiple] ? value.join(",") : value
83
91
  google_drive_resource[row_position, column.column_position] = assignment_value
84
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheets_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Gadad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-15 00:00:00.000000000 Z
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive