file_db 0.2.0 → 0.3.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 +4 -4
- data/README.md +12 -1
- data/lib/file_db/data.rb +4 -0
- data/lib/file_db/table.rb +18 -6
- data/lib/file_db/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642cea72c2a33e47d06c9b5ad6f5b0adfc162dad
|
4
|
+
data.tar.gz: c1cbd423a3ec0d42692b0d1edb4bae8958a3f080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dec0c4812a655998171231a3813345ace3a363f6ad75c0b17844326ebc7afe54cbf00ee2ba9cff6a89b60e55d903ce7895fe33b05025440b65d4a741dd0b4420
|
7
|
+
data.tar.gz: ce695c5f79f7f0fbb25cd82d6bec7a2f6a3251862afd51166ef76b426ca196132441e3a7a99850c40d8377d6fdafe30ca5fdc979b8b7ef636962d0988bc99977
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ You need to store data into a small type of database, like CSV and want a better
|
|
7
7
|
hm, yeah. just add this to your Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'file_db', '~> 0.
|
10
|
+
gem 'file_db', '~> 0.3.0'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -104,6 +104,17 @@ User.find(1466311874)
|
|
104
104
|
-> #<User:0x00000004651798 @name="bob", @id="1466311874", @email=test@example.com>
|
105
105
|
```
|
106
106
|
|
107
|
+
delete a record:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
user = User.find(1466311874)
|
111
|
+
-> #<User:0x00000004651798 @name="rob", @id="1466311874", @email=nil>
|
112
|
+
user.delete
|
113
|
+
User.find(1466311874)
|
114
|
+
-> nil
|
115
|
+
```
|
116
|
+
|
117
|
+
|
107
118
|
You want to use another table than `user`? So just configure it:
|
108
119
|
|
109
120
|
```ruby
|
data/lib/file_db/data.rb
CHANGED
data/lib/file_db/table.rb
CHANGED
@@ -15,12 +15,29 @@ module FileDb
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def rebuild_file! entries
|
19
|
+
::CSV.open(table_file_location, "w") do |csv|
|
20
|
+
entries.each do |entry|
|
21
|
+
csv << entry
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
def append_to_database entry_object
|
19
27
|
::CSV.open(table_file_location, "a") do |csv|
|
20
28
|
csv << entry_object.to_csv
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
32
|
+
def delete_entry entry
|
33
|
+
records = []
|
34
|
+
::CSV.foreach(table_file_location) do |row|
|
35
|
+
next if row[0]==entry.id.to_s
|
36
|
+
records << row
|
37
|
+
end
|
38
|
+
rebuild_file! records
|
39
|
+
end
|
40
|
+
|
24
41
|
def update_database entry_object
|
25
42
|
records = []
|
26
43
|
::CSV.foreach(table_file_location) do |row|
|
@@ -30,12 +47,7 @@ module FileDb
|
|
30
47
|
records << row
|
31
48
|
end
|
32
49
|
end
|
33
|
-
|
34
|
-
::CSV.open(table_file_location, "w") do |csv|
|
35
|
-
records.each do |record|
|
36
|
-
csv << record
|
37
|
-
end
|
38
|
-
end
|
50
|
+
rebuild_file! records
|
39
51
|
end
|
40
52
|
|
41
53
|
def table_file_location
|
data/lib/file_db/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.4.6
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Use CSV Files like a Database with ActiveRecord Feeling.
|