jsondb 0.0.2 → 0.1.1
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/lib/jsondb.rb +14 -5
- data/lib/jsondb/base.rb +29 -0
- data/lib/jsondb/commands.rb +56 -0
- data/lib/jsondb/constants.rb +23 -0
- data/lib/jsondb/db.rb +94 -57
- data/lib/jsondb/field.rb +80 -48
- data/lib/jsondb/fields.rb +55 -0
- data/lib/jsondb/file_ops.rb +64 -54
- data/lib/jsondb/logger.rb +36 -0
- data/lib/jsondb/record.rb +53 -88
- data/lib/jsondb/records.rb +62 -0
- data/lib/jsondb/result_set.rb +126 -0
- data/lib/jsondb/settings.rb +34 -0
- data/lib/jsondb/table.rb +93 -145
- data/lib/jsondb/tables.rb +78 -0
- data/lib/jsondb/validations.rb +133 -0
- metadata +12 -4
- data/lib/jsondb/resultset.rb +0 -109
- data/lib/jsondb/validation.rb +0 -88
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_pure
|
@@ -31,13 +31,21 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/jsondb.rb
|
34
|
+
- lib/jsondb/base.rb
|
35
|
+
- lib/jsondb/commands.rb
|
36
|
+
- lib/jsondb/constants.rb
|
34
37
|
- lib/jsondb/db.rb
|
35
38
|
- lib/jsondb/field.rb
|
39
|
+
- lib/jsondb/fields.rb
|
36
40
|
- lib/jsondb/file_ops.rb
|
41
|
+
- lib/jsondb/logger.rb
|
37
42
|
- lib/jsondb/record.rb
|
38
|
-
- lib/jsondb/
|
43
|
+
- lib/jsondb/records.rb
|
44
|
+
- lib/jsondb/result_set.rb
|
45
|
+
- lib/jsondb/settings.rb
|
39
46
|
- lib/jsondb/table.rb
|
40
|
-
- lib/jsondb/
|
47
|
+
- lib/jsondb/tables.rb
|
48
|
+
- lib/jsondb/validations.rb
|
41
49
|
homepage: http://fernandezvara.github.io/jsondb/
|
42
50
|
licenses:
|
43
51
|
- MIT
|
data/lib/jsondb/resultset.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
module JSONdb
|
2
|
-
class ResultSet
|
3
|
-
|
4
|
-
include Validation
|
5
|
-
|
6
|
-
def initialize(table_class, array_fields = nil)
|
7
|
-
@fields = array_fields || table_class.fields.to_hash.keys
|
8
|
-
# actually it deletes the record!
|
9
|
-
@result = Hash.new()
|
10
|
-
table_class.records.each do |k, v|
|
11
|
-
@result[k] = v.dup
|
12
|
-
end
|
13
|
-
|
14
|
-
@equal = Hash.new
|
15
|
-
@min = Hash.new
|
16
|
-
@max = Hash.new
|
17
|
-
@like = Hash.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def equal(field, value)
|
21
|
-
@equal[field] = value
|
22
|
-
return self
|
23
|
-
end
|
24
|
-
|
25
|
-
def min(field, value)
|
26
|
-
@min[field] = value
|
27
|
-
return self
|
28
|
-
end
|
29
|
-
|
30
|
-
def max(field, value)
|
31
|
-
@max[field] = value
|
32
|
-
return self
|
33
|
-
end
|
34
|
-
|
35
|
-
def like(field, value)
|
36
|
-
@like[field] = value
|
37
|
-
return self
|
38
|
-
end
|
39
|
-
|
40
|
-
def result
|
41
|
-
result_equal if @equal.keys.count != 0
|
42
|
-
result_min if @min.keys.count != 0
|
43
|
-
result_max if @max.keys.count != 0
|
44
|
-
result_like if @like.keys.count != 0
|
45
|
-
return @result
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def result_equal
|
51
|
-
@equal.each do |col_name, col_value|
|
52
|
-
this_result = Array.new
|
53
|
-
@result.each do |id, record|
|
54
|
-
r = record.send col_name.to_sym
|
55
|
-
if r == col_value
|
56
|
-
this_result << id
|
57
|
-
end
|
58
|
-
end
|
59
|
-
remove_if_key_not_in(this_result)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def result_min
|
64
|
-
@min.each do |col_name, col_value|
|
65
|
-
this_result = Array.new
|
66
|
-
@result.each do |id, record|
|
67
|
-
r = record.send col_name.to_sym
|
68
|
-
if r >= col_value
|
69
|
-
this_result << id
|
70
|
-
end
|
71
|
-
end
|
72
|
-
remove_if_key_not_in(this_result)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def result_max
|
77
|
-
@max.each do |col_name, col_value|
|
78
|
-
this_result = Array.new
|
79
|
-
@result.each do |id, record|
|
80
|
-
r = record.send col_name.to_sym
|
81
|
-
if r <= col_value
|
82
|
-
this_result << id
|
83
|
-
end
|
84
|
-
end
|
85
|
-
remove_if_key_not_in(this_result)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def result_like
|
90
|
-
@like.each do |col_name, col_value|
|
91
|
-
this_result = Array.new
|
92
|
-
@result.each do |id, record|
|
93
|
-
r = record.send col_name.to_sym
|
94
|
-
if r =~ Regexp.new(col_value)
|
95
|
-
this_result << id
|
96
|
-
end
|
97
|
-
end
|
98
|
-
remove_if_key_not_in(this_result)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def remove_if_key_not_in(arr)
|
103
|
-
@result.keys.each do |key|
|
104
|
-
@result.delete(key) if arr.include?(key) == false
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
data/lib/jsondb/validation.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
module JSONdb
|
2
|
-
module Validation
|
3
|
-
|
4
|
-
def allowed_types
|
5
|
-
["String", "Fixnum", "Integer", "Float", "Time", "Bool"]
|
6
|
-
end
|
7
|
-
|
8
|
-
def allowed_name?(name)
|
9
|
-
if (name =~ /^[a-zA-Z0-9_]+$/).nil?
|
10
|
-
raise "Name not allowed. /^[a-zA-Z0-9_]+$/"
|
11
|
-
else
|
12
|
-
return true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def allowed?(type)
|
17
|
-
if allowed_types.include?(type.to_s)
|
18
|
-
return type.to_s
|
19
|
-
else
|
20
|
-
raise "Validation: Type '#{type.to_s}' not allowed"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def validate_type(_class, _value)
|
25
|
-
case _class
|
26
|
-
when "Bool"
|
27
|
-
bool?(_class, _value)
|
28
|
-
when "String"
|
29
|
-
string?(_class, _value)
|
30
|
-
when "Fixnum", "Integer", "Float"
|
31
|
-
numeric?(_class, _value)
|
32
|
-
when "Time"
|
33
|
-
time?(_class, _value)
|
34
|
-
else
|
35
|
-
raise "Validation: '#{_class}' type not allowed"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def bool?(_class, _value)
|
42
|
-
case _value
|
43
|
-
when true, false
|
44
|
-
return _value
|
45
|
-
else
|
46
|
-
raise "Validation: Bool: Not a Bool type"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def string?(_class, _value)
|
51
|
-
if _class == _value.class.to_s
|
52
|
-
return _value
|
53
|
-
else
|
54
|
-
raise "Validation: #{_class}: Value '#{_value}' not allowed for '#{_class}' type"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def numeric?(_class, _value)
|
59
|
-
case _class
|
60
|
-
when "Fixnum", "Integer"
|
61
|
-
if _value.class.to_s == "Fixnum"
|
62
|
-
return _value
|
63
|
-
else
|
64
|
-
raise "Validation: '#{_value}' is not Integer"
|
65
|
-
end
|
66
|
-
when "Float"
|
67
|
-
case eval(_value).class.to_s
|
68
|
-
when "Float"
|
69
|
-
return _value
|
70
|
-
when "Fixnum"
|
71
|
-
return _value.to_f
|
72
|
-
else
|
73
|
-
raise "Validation: '#{_value} is not a Float type"
|
74
|
-
end
|
75
|
-
else
|
76
|
-
raise "Validation: '#{_value} is not a Numeric type"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def time?(_class, _value)
|
81
|
-
if eval(_value).class.to_s != "Time"
|
82
|
-
raise "Validation: '#{_value} is not a Time type"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|