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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbe8f5bbdd3696e6224062f8dba7de61aa9b8aae
4
- data.tar.gz: 5be8524e9786b61df961f487277c9914839066de
3
+ metadata.gz: ec92f4dc89f2633920502a33f1fc20b2c21cf8c4
4
+ data.tar.gz: 8c48bbe8570921690c3ea7b732a87ab84bc9f8fc
5
5
  SHA512:
6
- metadata.gz: 5c144a1f3daa5f40d7c17afaefb9e84f40c8799aef329f1d086be006de96c5999d76c0d7d7f100a8b8eb9a56e8dddce5cc9a5e2d8c915539d4b12588d8c82feb
7
- data.tar.gz: ace352a9f89ada96132a439acc61461c69e2c28547be305efbb039b138e4899ed524b8ac26cab3c81d414800d1f503658e11f6891ef3ee3b51f0008c92b8cf95
6
+ metadata.gz: 716f92939eeefba92fc83ce4bfc9b4242f8f79046c9dd947bdd8baf1d1fb115af8cafe0069d171acf31332b1450dd07915a0a5582a7e07cb40119dcf64cb7eb6
7
+ data.tar.gz: d19526b19c58b6c0d75a88c9270ab3d85ba432f1b39921ce93fd18bd13fab51adc728512ba61f881dbd1549ac24fef52d242cdf2475e6127a1c9028bc3cef3af
@@ -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')
@@ -2,9 +2,9 @@ module JSONdb
2
2
 
3
3
  @@settings = Settings.new
4
4
  @@constants = Constants.new
5
- @@tables = Hash.new
6
- @@fields = Hash.new
7
- @@records = Hash.new
5
+ @@tables = JSONdb::PaginatedHash.new
6
+ @@fields = JSONdb::PaginatedHash.new
7
+ @@records = JSONdb::PaginatedHash.new
8
8
 
9
9
 
10
10
  def self.settings
@@ -2,7 +2,7 @@ module JSONdb
2
2
 
3
3
  class Db
4
4
 
5
- attr_reader :created_at, :updated_at, :folder, :tables
5
+ attr_reader :created_at, :updated_at, :folder
6
6
 
7
7
  include JSONdb::Tables
8
8
  include JSONdb::Commands
@@ -6,7 +6,7 @@ module JSONdb
6
6
  include JSONdb::Validations::Types
7
7
  include JSONdb::Logger
8
8
 
9
- #attr_accessor :type, :nullable, :default
9
+ attr_accessor :name
10
10
 
11
11
  def initialize(name)
12
12
  @name = name if allowed_name?(name)
@@ -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
@@ -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
 
@@ -29,7 +29,7 @@ module JSONdb
29
29
  JSONdb.records[@name][record.id] = record
30
30
  end
31
31
 
32
- def drop_record(record)
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
@@ -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] = Hash.new
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(self.created_at)
48
+ Time.at(@created_at)
49
49
  end
50
50
 
51
51
  def updated_at
52
- Time.at(self.updated_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
@@ -13,6 +13,10 @@ module JSONdb
13
13
  end
14
14
  end
15
15
 
16
+ def tables
17
+ JSONdb.tables
18
+ end
19
+
16
20
  def table_names
17
21
  JSONdb.tables.keys
18
22
  end
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.5
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-02 00:00:00.000000000 Z
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_pure