dalton 0.0.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.
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ java_import "clojure.lang.PersistentHashSet"
4
+ java_import "java.util.HashSet"
5
+ java_import "clojure.lang.Keyword"
6
+
7
+ describe Dalton::Translation do
8
+
9
+ let(:ruby_set) { Set.new([:a, 1, Set.new([:b, 2])]) }
10
+ let(:clojure_set) {
11
+ PersistentHashSet.create([Keyword.intern('a'),
12
+ 1,
13
+ PersistentHashSet.create([Keyword.intern('b'),
14
+ 2
15
+ ])
16
+ ])
17
+ }
18
+
19
+ let(:datomic_entity) { Java::DatomicQuery::EntityMap.new(1, 2, 3, 4) }
20
+ let(:dalton_entity) { Dalton::Entity.new(datomic_entity) }
21
+
22
+ let(:ruby_keyword) { :xorn }
23
+ let(:clojure_keyword) { Keyword.intern('xorn') }
24
+
25
+ let(:ruby_keyword_datalog_variable) { :'?e' }
26
+ let(:clojure_symbol_datalog_variable) { Java::ClojureLang::Symbol.intern('?e') }
27
+
28
+ let(:ruby_keyword_datalog_source) { :'$' }
29
+ let(:clojure_symbol_datalog_source) { Java::ClojureLang::Symbol.intern('$') }
30
+
31
+ describe "#from_clj" do
32
+ context "with a (clojure) IPersistentSet" do
33
+ subject { Dalton::Translation.from_clj(clojure_set) }
34
+
35
+ it 'returns a ruby Set with translated members' do
36
+ expect(subject).to eq(ruby_set)
37
+ end
38
+ end
39
+
40
+ context "with a (clojure) Datomic entity" do
41
+ subject { Dalton::Translation.from_clj(datomic_entity) }
42
+
43
+ it 'wraps it in a Dalton entity' do
44
+ expect(subject).to eq(dalton_entity)
45
+ end
46
+ end
47
+
48
+ context "with a clojure Keyword" do
49
+ subject { Dalton::Translation.from_clj(clojure_keyword) }
50
+
51
+ it 'returns the equivalent ruby keyword' do
52
+ expect(subject).to eq(ruby_keyword)
53
+ end
54
+ end
55
+
56
+ context "with a clojure Symbol" do
57
+ subject { Dalton::Translation.from_clj(clojure_symbol_datalog_variable) }
58
+
59
+ it 'returns the equivalent ruby keyword' do
60
+ expect(subject).to eq(ruby_keyword_datalog_variable)
61
+ end
62
+ end
63
+
64
+ context "with a java.util.Date" do
65
+ subject {
66
+ format = Java::JavaText::SimpleDateFormat.new("yyyy-MM-dd HH:mm:ss Z")
67
+ Dalton::Translation.from_clj(format.parse("1998-07-05 07:00:00 -0000"))
68
+ }
69
+
70
+ it 'returns the equivalent ruby DateTime' do
71
+ expect(subject).to eq(DateTime.parse("1998-07-05 07:00:00 -0000"))
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ describe "#from_ruby" do
78
+ context "with a ruby Set" do
79
+ subject { Dalton::Translation.from_ruby(ruby_set) }
80
+
81
+ it 'returns a PersistentHashSet with translated members' do
82
+ expect(subject).to clojure_equal(clojure_set)
83
+ end
84
+ end
85
+
86
+ context "with a (ruby) Dalton entity" do
87
+ subject { Dalton::Translation.from_ruby(dalton_entity) }
88
+
89
+ it 'returns the enclosed Datomic entity' do
90
+ expect(subject).to equal(datomic_entity)
91
+ end
92
+ end
93
+
94
+ context "with a ruby Keyword starting with '?' (e.g. for use as a datalog variable)" do
95
+ subject { Dalton::Translation.from_ruby(ruby_keyword_datalog_variable) }
96
+
97
+ it 'returns the equivalent clojure symbol' do
98
+ expect(subject).to clojure_equal(clojure_symbol_datalog_variable)
99
+ end
100
+ end
101
+
102
+ context "with a ruby Keyword starting with '$' (e.g. for use as a datalog source)" do
103
+ subject { Dalton::Translation.from_ruby(ruby_keyword_datalog_source) }
104
+
105
+ it 'returns the equivalent clojure symbol' do
106
+ expect(subject).to clojure_equal(clojure_symbol_datalog_source)
107
+ end
108
+ end
109
+
110
+ context "with a ruby DateTime" do
111
+ subject {
112
+ Dalton::Translation.from_ruby(DateTime.parse("1998-07-05 07:00:00 -0000"))
113
+ }
114
+
115
+ let(:expected) {
116
+ format = Java::JavaText::SimpleDateFormat.new("yyyy-MM-dd HH:mm:ss Z")
117
+ format.parse("1998-07-05 07:00:00 -0000")
118
+ }
119
+
120
+ it 'returns the equivalent ruby DateTime' do
121
+ expect(subject).to eq(expected)
122
+ end
123
+ end
124
+ end
125
+ end
126
+
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ java_import "clojure.lang.Keyword"
4
+ java_import "clojure.lang.PersistentVector"
5
+ java_import "clojure.lang.IPersistentMap"
6
+
7
+ describe Dalton::Utility do
8
+ include Dalton::Utility
9
+
10
+ describe '#read_edn' do
11
+ it 'reads EDN' do
12
+ read_data = read_edn('[1 2 3]')
13
+ expected_data = PersistentVector.create([1, 2, 3])
14
+ expect(read_data).to eq(expected_data)
15
+ end
16
+
17
+ it 'understands tempid literal tags (#db/id)' do
18
+ tempid = read_edn('#db/id[:db.part/db]')
19
+ expect(tempid).to be_a(IPersistentMap)
20
+ expect(tempid[Keyword.intern('part')]).to eq(Keyword.intern('db.part/db'))
21
+ expect(tempid[Keyword.intern('idx')]).to be_a(Numeric)
22
+ expect(tempid[Keyword.intern('idx')]).to be < 0
23
+ end
24
+
25
+ it 'understands database function literal tags (#db/fn)' do
26
+ database_function = read_edn('#db/fn{:lang "clojure" :params [db foo] :code "(reverse foo)"}')
27
+ expect(database_function).to be_a(IPersistentMap)
28
+ # with complicated structure we probably don't need to test...
29
+ end
30
+ end
31
+
32
+ describe "#tag" do
33
+ it "tag a symbol with metadata" do
34
+ expect(meta(tag(sym('foo'), sym('String'))).to_edn).to eq('{:tag String}')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ require 'jbundler'
3
+ Bundler.require
4
+
5
+ require 'wrong/adapters/rspec'
6
+
7
+ def reload!
8
+ Object.send(:remove_const, :Dalton) if defined?(Dalton)
9
+ load './lib/dalton.rb'
10
+
11
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| load(f)}
12
+
13
+ true
14
+ end
15
+
16
+ reload!
17
+
18
+ RSpec.configure do |config|
19
+ config.backtrace_exclusion_patterns = []
20
+ config.backtrace_inclusion_patterns = []
21
+ end
@@ -0,0 +1,52 @@
1
+ require 'rspec/matchers'
2
+
3
+ module RSpec
4
+ module Matchers
5
+ module Dalton
6
+ class ClojureEqual < BuiltIn::BaseMatcher
7
+ def match(expected, actual)
8
+ ::Dalton::Utility.clojure_equal?(actual, expected)
9
+ end
10
+
11
+ def failure_message_for_should
12
+ return <<-MESSAGE
13
+
14
+ expected #{inspect_object(expected)}
15
+ got #{inspect_object(actual)}
16
+
17
+ Compared using clojure_equal?, which compares using clojure.core/=
18
+
19
+ MESSAGE
20
+ end
21
+
22
+ def failure_message_for_should_not
23
+ return <<-MESSAGE
24
+
25
+ expected not #{inspect_object(actual)}
26
+ got #{inspect_object(expected)}
27
+
28
+ Compared using clojure_equal?, which compares using clojure.core/=
29
+
30
+ MESSAGE
31
+ end
32
+
33
+ def diffable?; true; end
34
+
35
+ private
36
+
37
+ def inspect_object(o)
38
+ "#<#{o.class}:#{o.object_id}> => #{o.to_edn}"
39
+ end
40
+
41
+ def eq_expression
42
+ Expectations::Syntax.positive_expression("actual", "clojure_equal?(expected)")
43
+ end
44
+ end
45
+ end
46
+
47
+ def clojure_equal(expected)
48
+ Dalton::ClojureEqual.new(expected)
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ module DatomicContext
2
+ def self.included(base)
3
+ base.module_eval do
4
+ let(:uri) { 'datomic:mem://spec' }
5
+ # let(:uri) { 'datomic:dev://localhost:4334/spec' }
6
+ let(:conn) { Dalton::Connection.new(uri) }
7
+ let(:db) { conn.refresh }
8
+
9
+ before do
10
+ conn.create
11
+ conn.connect
12
+ end
13
+
14
+ after do
15
+ conn.destroy
16
+ end
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dalton
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Jenkins
8
+ - Joshua Bates
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: zweikopf
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.4.0
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - '='
24
+ - !ruby/object:Gem::Version
25
+ version: 0.4.0
26
+ prerelease: false
27
+ type: :runtime
28
+ description: Dalton attempts to give low level access to Datomic from JRuby
29
+ email:
30
+ - brian@brianjenkins.org
31
+ - joshua@goodguide.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - .jrubyrc
38
+ - .ruby-version
39
+ - Gemfile
40
+ - Jarfile
41
+ - README.md
42
+ - Rakefile
43
+ - dalton.gemspec
44
+ - epl-v10.html
45
+ - examples/posts_controller.rb
46
+ - lib/dalton.rb
47
+ - lib/dalton/attribute.rb
48
+ - lib/dalton/connection.rb
49
+ - lib/dalton/database.rb
50
+ - lib/dalton/datomization.rb
51
+ - lib/dalton/entity.rb
52
+ - lib/dalton/exception.rb
53
+ - lib/dalton/transaction_result.rb
54
+ - lib/dalton/translation.rb
55
+ - lib/dalton/undatomization.rb
56
+ - lib/dalton/utility.rb
57
+ - lib/dalton/version.rb
58
+ - spec/dalton/connection_spec.rb
59
+ - spec/dalton/database_spec.rb
60
+ - spec/dalton/datomization_spec.rb
61
+ - spec/dalton/entity_spec.rb
62
+ - spec/dalton/translation_spec.rb
63
+ - spec/dalton/utility_spec.rb
64
+ - spec/spec_helper.rb
65
+ - spec/support/clojure_equal_matcher.rb
66
+ - spec/support/datomic_context.rb
67
+ homepage: ''
68
+ licenses:
69
+ - EPL
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.1.9
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: A thin Datomic driver for JRuby
91
+ test_files:
92
+ - spec/dalton/connection_spec.rb
93
+ - spec/dalton/database_spec.rb
94
+ - spec/dalton/datomization_spec.rb
95
+ - spec/dalton/entity_spec.rb
96
+ - spec/dalton/translation_spec.rb
97
+ - spec/dalton/utility_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/support/clojure_equal_matcher.rb
100
+ - spec/support/datomic_context.rb
101
+ has_rdoc: