hypostasis 0.1.1 → 0.2.0

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: fb31443e0e30e596eee33533e9bf70bf207df3b6
4
- data.tar.gz: b5753b79d36c1fec6000a0bb20bac292383b0db7
3
+ metadata.gz: 8f4adf685f294fec93972358ba0f44f733ca1711
4
+ data.tar.gz: 0430fec44b635d781d0d6a576cf4013afb7f0824
5
5
  SHA512:
6
- metadata.gz: 72f6be472948ea18c1ac60df3d8503f61cc58be05f20a572b7d81a5a626dbe826ce7f5ad89513aa13f8396d89ba0762d5006a3796a66c8c8b5d385b52d590c3e
7
- data.tar.gz: 492764de3d86804dd84e195944b3c3b2cbc9bf144ecb60e50f5fd6db92e75888a9274275c20d9e91d09189a53b39943b617b818e8d7b4667ceb3fcc940df8e65
6
+ metadata.gz: c44ccc9c76c56b257e3f86782995efbe96e01ad400fb1f098861c1bb31482cb774539f9a35edeb6759c30bc7e60637205c918750a0294a29d3fb793020b8349c
7
+ data.tar.gz: 4651931a11a248d52845b6c57c8f697211983c28e6bb72fe2f1ae5b2319e8bfad43b778d20c7a74e4c8698e49985251e78a2df4264352082aa997b7c746cd8ce
data/.travis.yml CHANGED
@@ -3,44 +3,44 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
- - ruby-head
6
+ # - ruby-head
7
7
  - jruby-19mode
8
- - jruby-head
8
+ # - jruby-head
9
9
  jdk:
10
10
  - openjdk6
11
11
  - openjdk7
12
12
  - oraclejdk7
13
- - oraclejdk8
13
+ # - oraclejdk8
14
14
  matrix:
15
15
  exclude:
16
16
  - rvm: 1.9.3
17
17
  jdk: openjdk6
18
18
  - rvm: 1.9.3
19
19
  jdk: oraclejdk7
20
- - rvm: 1.9.3
21
- jdk: oraclejdk8
20
+ # - rvm: 1.9.3
21
+ # jdk: oraclejdk8
22
22
  - rvm: 2.0.0
23
23
  jdk: openjdk6
24
24
  - rvm: 2.0.0
25
25
  jdk: oraclejdk7
26
- - rvm: 2.0.0
27
- jdk: oraclejdk8
26
+ # - rvm: 2.0.0
27
+ # jdk: oraclejdk8
28
28
  - rvm: 2.1.0
29
29
  jdk: openjdk6
30
30
  - rvm: 2.1.0
31
31
  jdk: oraclejdk7
32
- - rvm: 2.1.0
33
- jdk: oraclejdk8
34
- - rvm: ruby-head
35
- jdk: openjdk6
36
- - rvm: ruby-head
37
- jdk: oraclejdk7
38
- - rvm: ruby-head
39
- jdk: oraclejdk8
40
- allow_failures:
41
- - rvm: ruby-head
42
- - rvm: jruby-head
43
- - jdk: oraclejdk8
32
+ # - rvm: 2.1.0
33
+ # jdk: oraclejdk8
34
+ # - rvm: ruby-head
35
+ # jdk: openjdk6
36
+ # - rvm: ruby-head
37
+ # jdk: oraclejdk7
38
+ # - rvm: ruby-head
39
+ # jdk: oraclejdk8
40
+ # allow_failures:
41
+ # - rvm: ruby-head
42
+ # - rvm: jruby-head
43
+ # - jdk: oraclejdk8
44
44
  before_install:
45
45
  - wget https://foundationdb.com/downloads/I_accept_the_FoundationDB_Community_License_Agreement/1.0.1/foundationdb-clients_1.0.1-1_amd64.deb
46
46
  - wget https://foundationdb.com/downloads/I_accept_the_FoundationDB_Community_License_Agreement/1.0.1/foundationdb-server_1.0.1-1_amd64.deb
@@ -1,4 +1,5 @@
1
1
  module Hypostasis::DataModels; end
2
2
 
3
+ require 'hypostasis/data_models/utilities'
3
4
  require 'hypostasis/data_models/key_value'
4
5
  require 'hypostasis/data_models/document'
@@ -1,6 +1,8 @@
1
1
  require 'date'
2
2
 
3
3
  module Hypostasis::DataModels::KeyValue
4
+ include Hypostasis::DataModels::Utilities
5
+
4
6
  def set(key, value)
5
7
  key_path = "#{name}\\#{Hypostasis::Tuple.new(key.to_s, value.class.to_s).to_s}"
6
8
  database.set(key_path, value.to_s)
@@ -10,28 +12,6 @@ module Hypostasis::DataModels::KeyValue
10
12
  key_path = "#{name}\\#{Hypostasis::Tuple.new(key.to_s).to_s}"
11
13
  key = database.get_range_start_with(key_path).first.key
12
14
  value = database.get_range_start_with(key_path).first.value
13
- data_type = Hypostasis::Tuple.unpack(key.to_s.split('\\').last).to_a.last
14
- case data_type
15
- when 'Fixnum'
16
- Integer(value)
17
- when 'Bignum'
18
- Integer(value)
19
- when 'Float'
20
- Float(value)
21
- when 'String'
22
- value
23
- when 'Date'
24
- Date.parse(value)
25
- when 'DateTime'
26
- DateTime.parse(value)
27
- when 'Time'
28
- Time.parse(value)
29
- when 'TrueClass'
30
- true
31
- when 'FalseClass'
32
- false
33
- else
34
- raise Hypostasis::Errors::UnknownValueType
35
- end
15
+ reconstitute_value(Hypostasis::Tuple.unpack(key.to_s.split('\\').last), value)
36
16
  end
37
17
  end
@@ -0,0 +1,27 @@
1
+ module Hypostasis::DataModels::Utilities
2
+ def reconstitute_value(tuple, raw_value)
3
+ data_type = tuple.to_a.last
4
+ case data_type
5
+ when 'Fixnum'
6
+ Integer(raw_value)
7
+ when 'Bignum'
8
+ Integer(raw_value)
9
+ when 'Float'
10
+ Float(raw_value)
11
+ when 'String'
12
+ raw_value
13
+ when 'Date'
14
+ Date.parse(raw_value)
15
+ when 'DateTime'
16
+ DateTime.parse(raw_value)
17
+ when 'Time'
18
+ Time.parse(raw_value)
19
+ when 'TrueClass'
20
+ true
21
+ when 'FalseClass'
22
+ false
23
+ else
24
+ raise Hypostasis::Errors::UnknownValueType
25
+ end
26
+ end
27
+ end
@@ -27,6 +27,12 @@ module Hypostasis::Document
27
27
  self
28
28
  end
29
29
 
30
+ def destroy
31
+ self.class.namespace.transact do |tr|
32
+ tr.clear_range_start_with(self.class.namespace.for_document(self))
33
+ end
34
+ end
35
+
30
36
  def generate_id
31
37
  @id ||= SecureRandom.uuid
32
38
  end
@@ -36,6 +42,8 @@ module Hypostasis::Document
36
42
  end
37
43
 
38
44
  module ClassMethods
45
+ include Hypostasis::DataModels::Utilities
46
+
39
47
  def use_namespace(namespace)
40
48
  @@namespace = Hypostasis::Namespace.new(namespace.to_s, :document)
41
49
  end
@@ -49,11 +57,8 @@ module Hypostasis::Document
49
57
  end
50
58
 
51
59
  def field(name, options = {})
52
- named = name.to_s
53
- raise Hypostasis::Errors::MustDefineFieldType if options[:type].nil?
54
- raise Hypostasis::Errors::UnsupportedFieldType unless supported_field_types.include?(options[:type].to_s)
55
60
  register_field(name.to_sym)
56
- create_accessors(named, options)
61
+ create_accessors(name.to_s, options)
57
62
  end
58
63
 
59
64
  def fields
@@ -72,6 +77,10 @@ module Hypostasis::Document
72
77
  end
73
78
  end
74
79
 
80
+ def create(*attributes)
81
+ self.new(*attributes).save
82
+ end
83
+
75
84
  def find(id)
76
85
  document_keys = []
77
86
  namespace.transact do |tr|
@@ -91,31 +100,5 @@ module Hypostasis::Document
91
100
  document.set_id(id)
92
101
  document
93
102
  end
94
-
95
- def reconstitute_value(tuple, raw_value)
96
- data_type = tuple.to_a.last
97
- case data_type
98
- when 'Fixnum'
99
- Integer(raw_value)
100
- when 'Bignum'
101
- Integer(raw_value)
102
- when 'Float'
103
- Float(raw_value)
104
- when 'String'
105
- raw_value
106
- when 'Date'
107
- Date.parse(raw_value)
108
- when 'DateTime'
109
- DateTime.parse(raw_value)
110
- when 'Time'
111
- Time.parse(raw_value)
112
- when 'TrueClass'
113
- true
114
- when 'FalseClass'
115
- false
116
- else
117
- raise Hypostasis::Errors::UnknownValueType
118
- end
119
- end
120
103
  end
121
104
  end
@@ -1,3 +1,3 @@
1
1
  module Hypostasis
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -25,6 +25,24 @@ describe Hypostasis::Document do
25
25
 
26
26
  it { subject.must_respond_to :save }
27
27
 
28
+ describe '#create' do
29
+ let(:subject) { SampleDocument.create(name: 'John', age: 21, dob: Date.today.prev_year(21)) }
30
+ let(:document_tuple) { Hypostasis::Tuple.new(SampleDocument.to_s, subject.id.to_s).to_s }
31
+
32
+ def field_path(name, type)
33
+ 'sample_docs\\' + document_tuple + '\\' + Hypostasis::Tuple.new(name.to_s, type.to_s).to_s
34
+ end
35
+
36
+ after do
37
+ subject.destroy
38
+ end
39
+
40
+ it { subject.id.wont_be_nil }
41
+ it { database.get(field_path(:name, String)).must_equal 'John' }
42
+ it { database.get(field_path(:age, Fixnum)).must_equal '21' }
43
+ it { database.get(field_path(:dob, Date)).must_equal Date.today.prev_year(21).to_s }
44
+ end
45
+
28
46
  describe '#save' do
29
47
  let(:document_tuple) { Hypostasis::Tuple.new(SampleDocument.to_s, @document.id.to_s).to_s }
30
48
 
@@ -47,4 +65,8 @@ describe Hypostasis::Document do
47
65
  it { SampleDocument.find(document_id).is_a?(SampleDocument).must_equal true }
48
66
  it { SampleDocument.find(document_id).id.must_equal document_id }
49
67
  end
68
+
69
+ describe 'indexing' do
70
+
71
+ end
50
72
  end
@@ -3,7 +3,7 @@ class SampleDocument
3
3
 
4
4
  use_namespace 'sample_docs'
5
5
 
6
- field :name, type: String
7
- field :age, type: Fixnum
8
- field :dob, type: Date
6
+ field :name
7
+ field :age
8
+ field :dob
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypostasis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson
@@ -86,6 +86,7 @@ files:
86
86
  - lib/hypostasis/data_models.rb
87
87
  - lib/hypostasis/data_models/document.rb
88
88
  - lib/hypostasis/data_models/key_value.rb
89
+ - lib/hypostasis/data_models/utilities.rb
89
90
  - lib/hypostasis/document.rb
90
91
  - lib/hypostasis/errors.rb
91
92
  - lib/hypostasis/key_path.rb