jsondb 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsondb.rb +2 -0
- data/lib/jsondb/base.rb +3 -3
- data/lib/jsondb/db.rb +1 -1
- data/lib/jsondb/field.rb +1 -1
- data/lib/jsondb/fields.rb +2 -0
- data/lib/jsondb/record.rb +15 -0
- data/lib/jsondb/records.rb +3 -1
- data/lib/jsondb/table.rb +5 -5
- data/lib/jsondb/tables.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec92f4dc89f2633920502a33f1fc20b2c21cf8c4
|
4
|
+
data.tar.gz: 8c48bbe8570921690c3ea7b732a87ab84bc9f8fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 716f92939eeefba92fc83ce4bfc9b4242f8f79046c9dd947bdd8baf1d1fb115af8cafe0069d171acf31332b1450dd07915a0a5582a7e07cb40119dcf64cb7eb6
|
7
|
+
data.tar.gz: d19526b19c58b6c0d75a88c9270ab3d85ba432f1b39921ce93fd18bd13fab51adc728512ba61f881dbd1549ac24fef52d242cdf2475e6127a1c9028bc3cef3af
|
data/lib/jsondb.rb
CHANGED
@@ -3,6 +3,8 @@ require 'json/pure'
|
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
5
|
this_dir = File.dirname(__FILE__)
|
6
|
+
require File.join(this_dir, 'jsondb/paginated_hash')
|
7
|
+
|
6
8
|
require File.join(this_dir, 'jsondb/constants')
|
7
9
|
require File.join(this_dir, 'jsondb/logger')
|
8
10
|
require File.join(this_dir, 'jsondb/validations')
|
data/lib/jsondb/base.rb
CHANGED
@@ -2,9 +2,9 @@ module JSONdb
|
|
2
2
|
|
3
3
|
@@settings = Settings.new
|
4
4
|
@@constants = Constants.new
|
5
|
-
@@tables =
|
6
|
-
@@fields =
|
7
|
-
@@records =
|
5
|
+
@@tables = JSONdb::PaginatedHash.new
|
6
|
+
@@fields = JSONdb::PaginatedHash.new
|
7
|
+
@@records = JSONdb::PaginatedHash.new
|
8
8
|
|
9
9
|
|
10
10
|
def self.settings
|
data/lib/jsondb/db.rb
CHANGED
data/lib/jsondb/field.rb
CHANGED
data/lib/jsondb/fields.rb
CHANGED
@@ -11,10 +11,12 @@ module JSONdb
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_field(name)
|
14
|
+
@persisted = false
|
14
15
|
JSONdb.fields[@name][name] = Field.new(name)
|
15
16
|
end
|
16
17
|
|
17
18
|
def drop_field(name)
|
19
|
+
@persisted = false
|
18
20
|
JSONdb.fields[@name][name] = nil
|
19
21
|
JSONdb.fields[@name].delete(name)
|
20
22
|
end
|
data/lib/jsondb/record.rb
CHANGED
@@ -36,6 +36,21 @@ module JSONdb
|
|
36
36
|
return @record[name]
|
37
37
|
end
|
38
38
|
|
39
|
+
def data_from_hash(hash)
|
40
|
+
hash.each do |key, value|
|
41
|
+
@record[key] = value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# def created_at
|
47
|
+
# Time.at(@created_at)
|
48
|
+
# end
|
49
|
+
|
50
|
+
# def updated_at
|
51
|
+
# Time.at(@updated_at)
|
52
|
+
# end
|
53
|
+
|
39
54
|
def method_missing(name, *args)
|
40
55
|
name = name.to_s
|
41
56
|
|
data/lib/jsondb/records.rb
CHANGED
@@ -29,7 +29,7 @@ module JSONdb
|
|
29
29
|
JSONdb.records[@name][record.id] = record
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def delete_record(record)
|
33
33
|
begin
|
34
34
|
@persisted = false
|
35
35
|
JSONdb.records[@name][record.id] = nil
|
@@ -41,6 +41,8 @@ module JSONdb
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
alias :drop_record :delete_record
|
45
|
+
|
44
46
|
def exists?(record)
|
45
47
|
!JSONdb.records[@name][record.id].nil?
|
46
48
|
end
|
data/lib/jsondb/table.rb
CHANGED
@@ -7,7 +7,7 @@ module JSONdb
|
|
7
7
|
include JSONdb::Fields
|
8
8
|
include JSONdb::Records
|
9
9
|
|
10
|
-
attr_reader :persisted
|
10
|
+
attr_reader :persisted, :name
|
11
11
|
attr_accessor :timestamp, :created_at, :updated_at, :last_id
|
12
12
|
|
13
13
|
def initialize(name, new_table = true)
|
@@ -15,7 +15,7 @@ module JSONdb
|
|
15
15
|
|
16
16
|
@persisted = false
|
17
17
|
|
18
|
-
JSONdb.records[@name] =
|
18
|
+
JSONdb.records[@name] = JSONdb::PaginatedHash.new
|
19
19
|
JSONdb.fields[@name] = Hash.new
|
20
20
|
|
21
21
|
set_defaults
|
@@ -45,11 +45,11 @@ module JSONdb
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def created_at
|
48
|
-
Time.at(
|
48
|
+
Time.at(@created_at)
|
49
49
|
end
|
50
50
|
|
51
51
|
def updated_at
|
52
|
-
Time.at(
|
52
|
+
Time.at(@updated_at)
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
@@ -76,7 +76,7 @@ module JSONdb
|
|
76
76
|
|
77
77
|
records_in_file = @file.contents
|
78
78
|
|
79
|
-
JSONdb.records[@name] = Hash.new
|
79
|
+
# JSONdb.records[@name] = Hash.new
|
80
80
|
records_in_file.each do |key, values|
|
81
81
|
JSONdb.records[@name][values['id']] = Record.new(@name, values)
|
82
82
|
end
|
data/lib/jsondb/tables.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsondb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_pure
|