local_model 0.1.10 → 0.1.11

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
  SHA256:
3
- metadata.gz: 8851a543d6b05aff962d00d160c7e38c5d770e880b38131bb7f417e51c7e1a35
4
- data.tar.gz: 20e8e5b027a36a7e4a99d142a21a07797563ca024ec3e24be1c55e8b14b663e2
3
+ metadata.gz: b0802a175ec198bcfbcf75e72ff213a66acd4fc7d4a9e306325e264425dd2de3
4
+ data.tar.gz: 96943f1468780910bb17f24d2a2fc2201b4b907e322c77a7744b2885964f8447
5
5
  SHA512:
6
- metadata.gz: c75fb02836ac60ec9f916fe545a8d1af7ba95895f94f217379ef9086e2140f7489b4ad879b5efcf7a183be666e2a0ec4beb38854556fff96e87eeb2423d79101
7
- data.tar.gz: c9c72999f0f71fc98ba75563cbacf4114678dc4e9343cdbe49327db35564c2324633f1fc08edd348790e2df795fb7c3dbaaed41c876d49dcd2b9ccb73a1be9ba
6
+ metadata.gz: aa83e09b70e90ebdc8b379ad7dba73fd625056d0098079831a3e1f100907f3dc1ccaecde0f4c8e750c813ae8ee4a9f3d3b76e58be2127bfb6db1bd9d4f202c71
7
+ data.tar.gz: cd5fc6d3004722f0e4348b7321b9dcead5525abefa4fbc8720076db526ea26d98fced45b3bb79e3d3804e4a9e19457a8a9b1d3d4e4bae7c987f28a9b4c240ac0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- local_model (0.1.9)
4
+ local_model (0.1.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/local_model.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require_relative "./local_model/version"
2
2
  require 'csv'
3
+ require_relative './local_model/errors/record_invalid'
4
+ require_relative './local_model/errors/record_not_found'
3
5
  require_relative './local_model/sandbox'
4
6
  require_relative './local_model/collection'
5
7
  require_relative './local_model/adapters/boolean_adapter'
@@ -218,6 +218,12 @@ module CSVInteractable
218
218
  end
219
219
  end
220
220
 
221
+ def save!
222
+ if !save
223
+ raise LocalModel::RecordInvalid
224
+ end
225
+ end
226
+
221
227
  end
222
228
 
223
229
  end
@@ -22,7 +22,7 @@ class LocalModel::CSV < LocalModel::Model
22
22
  end
23
23
 
24
24
  self.define_singleton_method :columns do
25
- cols
25
+ cols
26
26
  end
27
27
 
28
28
  schema_data = cols.each_with_index.reduce({}) do |mem, (key,i)|
@@ -52,6 +52,12 @@ class LocalModel::CSV < LocalModel::Model
52
52
  all_instances
53
53
  end
54
54
 
55
+ def self.count
56
+ total = 0
57
+ self.each_record{ total += 1 }
58
+ total
59
+ end
60
+
55
61
  def self.destroy_all
56
62
  self.all.each{ |obj| obj.destroy }
57
63
  end
@@ -105,12 +111,27 @@ class LocalModel::CSV < LocalModel::Model
105
111
  return self.find_by(id: id)
106
112
  end
107
113
 
114
+ def self.find!(id)
115
+ found_record = find(id)
116
+ if !found_record
117
+ raise LocalModel::RecordNotFound.new
118
+ else
119
+ found_record
120
+ end
121
+ end
122
+
108
123
  def self.create(**args)
109
124
  inst = new(**args)
110
125
  inst.save
111
126
  inst
112
127
  end
113
128
 
129
+ def self.create!(**args)
130
+ inst = new(**args)
131
+ inst.save!
132
+ inst
133
+ end
134
+
114
135
  def initialize(**args)
115
136
  args.each do |k,v|
116
137
  self.send("#{k}=", v)
@@ -121,6 +142,11 @@ class LocalModel::CSV < LocalModel::Model
121
142
  def saved?
122
143
  !self.id.nil?
123
144
  end
145
+
146
+ def reload
147
+ raise LocalModel::RecordNotFound if !self.id
148
+ self.class.find!(self.id)
149
+ end
124
150
 
125
151
  def destroy
126
152
  self.class.delete_row({id: self.id})
@@ -0,0 +1,4 @@
1
+ class LocalModel::RecordInvalid < StandardError
2
+
3
+
4
+ end
@@ -0,0 +1,3 @@
1
+ class LocalModel::RecordNotFound < StandardError
2
+
3
+ end
@@ -1,3 +1,3 @@
1
1
  module LocalModel
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Shute
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-01 00:00:00.000000000 Z
11
+ date: 2021-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,8 @@ files:
80
80
  - lib/local_model/collection.rb
81
81
  - lib/local_model/concerns/csv_interactable.rb
82
82
  - lib/local_model/csv.rb
83
+ - lib/local_model/errors/record_invalid.rb
84
+ - lib/local_model/errors/record_not_found.rb
83
85
  - lib/local_model/helpers/functions.rb
84
86
  - lib/local_model/helpers/pluralized_words.rb
85
87
  - lib/local_model/model.rb