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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/local_model.rb +2 -0
- data/lib/local_model/concerns/csv_interactable.rb +6 -0
- data/lib/local_model/csv.rb +27 -1
- data/lib/local_model/errors/record_invalid.rb +4 -0
- data/lib/local_model/errors/record_not_found.rb +3 -0
- data/lib/local_model/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0802a175ec198bcfbcf75e72ff213a66acd4fc7d4a9e306325e264425dd2de3
|
4
|
+
data.tar.gz: 96943f1468780910bb17f24d2a2fc2201b4b907e322c77a7744b2885964f8447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa83e09b70e90ebdc8b379ad7dba73fd625056d0098079831a3e1f100907f3dc1ccaecde0f4c8e750c813ae8ee4a9f3d3b76e58be2127bfb6db1bd9d4f202c71
|
7
|
+
data.tar.gz: cd5fc6d3004722f0e4348b7321b9dcead5525abefa4fbc8720076db526ea26d98fced45b3bb79e3d3804e4a9e19457a8a9b1d3d4e4bae7c987f28a9b4c240ac0
|
data/Gemfile.lock
CHANGED
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'
|
data/lib/local_model/csv.rb
CHANGED
@@ -22,7 +22,7 @@ class LocalModel::CSV < LocalModel::Model
|
|
22
22
|
end
|
23
23
|
|
24
24
|
self.define_singleton_method :columns do
|
25
|
-
|
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})
|
data/lib/local_model/version.rb
CHANGED
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.
|
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-
|
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
|