file_db 0.4.3 → 0.5.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 +21 -20
- data/file_db.gemspec +0 -1
- data/lib/file_db/data.rb +15 -1
- data/lib/file_db/version.rb +1 -1
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87178fd3990a62e452fcaec537b440e7e8cd3d1e
|
4
|
+
data.tar.gz: 0c5859ca95b0ceaf41e1c9b6f84c2203eb4751c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93690b7267241a8d7241ffa6a94b78e8c53fb68604818a1667b9f6310dc8481b37c587e52957e5b6b3ee7cb10e49afc8a8c0c4f9c57a37d1a19ee73afd6a22c2
|
7
|
+
data.tar.gz: 9fd4bc2856b480005d1f8af579e6e1a27ce4bbaee6eecdc3e580815b62920b6b81988b0ba035384b860abb29d170848dced1d8dacec2ab39c163c44c7187afed
|
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.5.0'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -30,13 +30,14 @@ First configure the storage directory:
|
|
30
30
|
```ruby
|
31
31
|
FileDb::Configuration.configure data_directory: 'data'
|
32
32
|
```
|
33
|
+
Subdirectory is the default for storing the tables. If you change the configuration, the `database_check!` will be automaticly executed
|
33
34
|
|
34
|
-
|
35
|
+
If you running a clean instance with no configuration changes so make sure, the storage directory exists or use the build in check for checking and creating the data directory:
|
35
36
|
```ruby
|
36
37
|
FileDb::Database.database_check!
|
37
38
|
```
|
38
39
|
|
39
|
-
|
40
|
+
Let's start with creating a model called `User`.
|
40
41
|
|
41
42
|
```ruby
|
42
43
|
class User < FileDb::Model
|
@@ -44,7 +45,7 @@ class User < FileDb::Model
|
|
44
45
|
end
|
45
46
|
```
|
46
47
|
|
47
|
-
|
48
|
+
Now we got a user model which actually just storing an id. lets add some `columns` for this.
|
48
49
|
|
49
50
|
```ruby
|
50
51
|
class User < FileDb::Model
|
@@ -61,7 +62,7 @@ my_user.save
|
|
61
62
|
now the `User` is stored under `data/user.csv`. You should find an entry like this one:
|
62
63
|
|
63
64
|
```
|
64
|
-
|
65
|
+
1,rob,
|
65
66
|
```
|
66
67
|
|
67
68
|
You can also use `create` to create it directly without calling save:
|
@@ -73,14 +74,14 @@ my_user = User.create name: 'rob'
|
|
73
74
|
|
74
75
|
Let's get them user back:
|
75
76
|
```ruby
|
76
|
-
User.find
|
77
|
-
-> #<User:0x00000004651798 @name="rob", @id="
|
77
|
+
User.find 1
|
78
|
+
-> #<User:0x00000004651798 @name="rob", @id="1", @email=nil>
|
78
79
|
```
|
79
80
|
|
80
81
|
you can access all attributes like `attr_accessor`
|
81
82
|
|
82
83
|
```ruby
|
83
|
-
User.find(
|
84
|
+
User.find(1).name
|
84
85
|
-> rob
|
85
86
|
```
|
86
87
|
|
@@ -89,53 +90,53 @@ Let's find all users named with rob. I think you know how get this to work:
|
|
89
90
|
|
90
91
|
```ruby
|
91
92
|
User.where(name: 'rob')
|
92
|
-
-> [#<User:0x00000004651798 @name="rob", @id="
|
93
|
+
-> [#<User:0x00000004651798 @name="rob", @id="1", @email=nil>]
|
93
94
|
```
|
94
95
|
|
95
96
|
It's also fine to search with more than one parameter.
|
96
97
|
|
97
98
|
```ruby
|
98
99
|
User.where(name: 'rob', email: nil)
|
99
|
-
-> [#<User:0x00000004651798 @name="rob", @id="
|
100
|
+
-> [#<User:0x00000004651798 @name="rob", @id="1", @email=nil>]
|
100
101
|
```
|
101
102
|
|
102
103
|
You can also use `first` and `last` to get the first and last user
|
103
104
|
```ruby
|
104
105
|
User.first
|
105
|
-
-> #<User:0x00000004651798 @name="rob", @id="
|
106
|
+
-> #<User:0x00000004651798 @name="rob", @id="1", @email=nil>
|
106
107
|
```
|
107
108
|
|
108
109
|
```ruby
|
109
110
|
User.last
|
110
|
-
-> #<User:0x00000004651798 @name="rob", @id="
|
111
|
+
-> #<User:0x00000004651798 @name="rob", @id="1", @email=nil>
|
111
112
|
```
|
112
113
|
|
113
114
|
Or you use `all` to get really all users.
|
114
115
|
|
115
116
|
```ruby
|
116
117
|
User.all
|
117
|
-
-> [#<User:0x00000004651798 @name="rob", @id="
|
118
|
+
-> [#<User:0x00000004651798 @name="rob", @id="1", @email=nil>]
|
118
119
|
```
|
119
120
|
|
120
121
|
rename the user:
|
121
122
|
|
122
123
|
```ruby
|
123
|
-
user = User.find(
|
124
|
-
-> #<User:0x00000004651798 @name="rob", @id="
|
124
|
+
user = User.find(1)
|
125
|
+
-> #<User:0x00000004651798 @name="rob", @id="1", @email=nil>
|
125
126
|
user.name = 'bob'
|
126
127
|
user.email = 'test@example.com'
|
127
128
|
user.save
|
128
|
-
User.find(
|
129
|
-
-> #<User:0x00000004651798 @name="bob", @id="
|
129
|
+
User.find(1)
|
130
|
+
-> #<User:0x00000004651798 @name="bob", @id="1", @email=test@example.com>
|
130
131
|
```
|
131
132
|
|
132
133
|
delete a record:
|
133
134
|
|
134
135
|
```ruby
|
135
|
-
user = User.find(
|
136
|
-
-> #<User:0x00000004651798 @name="rob", @id="
|
136
|
+
user = User.find(1)
|
137
|
+
-> #<User:0x00000004651798 @name="rob", @id="1", @email=nil>
|
137
138
|
user.delete
|
138
|
-
User.find(
|
139
|
+
User.find(1)
|
139
140
|
-> nil
|
140
141
|
```
|
141
142
|
|
data/file_db.gemspec
CHANGED
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.12"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
-
spec.add_development_dependency "timecop", "~> 0.8"
|
26
25
|
spec.required_ruby_version = '>= 1.9.3'
|
27
26
|
end
|
data/lib/file_db/data.rb
CHANGED
@@ -12,7 +12,7 @@ module FileDb
|
|
12
12
|
if persisted?
|
13
13
|
Database.instance.update_record self
|
14
14
|
else
|
15
|
-
self.id = Time.now.to_i
|
15
|
+
self.id = next_id #Time.now.to_i
|
16
16
|
Database.instance.add_record self
|
17
17
|
end
|
18
18
|
end
|
@@ -23,6 +23,20 @@ module FileDb
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
+
def next_id
|
27
|
+
return 1 unless current_id
|
28
|
+
current_id + 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def current_id
|
32
|
+
return unless last_record
|
33
|
+
last_record.id.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def last_record
|
37
|
+
self.class.last
|
38
|
+
end
|
39
|
+
|
26
40
|
def load_params_into_model params
|
27
41
|
params.each do |key, value|
|
28
42
|
next unless self.class.columns.include?(key)
|
data/lib/file_db/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starke
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: timecop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.8'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.8'
|
69
55
|
description: You need to store informationen in a CSV File, because there is no need
|
70
56
|
for a database? You can use FileDb to store all informationen in a CSV File and
|
71
57
|
search in it like ActiveRecord (User.find(1212). See detailed Information at the
|