marklogic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +10 -0
  3. data/.gitignore +15 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +17 -0
  8. data/Guardfile +45 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +31 -0
  11. data/Rakefile +6 -0
  12. data/lib/marklogic.rb +21 -0
  13. data/lib/marklogic/app_server.rb +60 -0
  14. data/lib/marklogic/application.rb +244 -0
  15. data/lib/marklogic/collection.rb +265 -0
  16. data/lib/marklogic/connection.rb +308 -0
  17. data/lib/marklogic/consts.rb +35 -0
  18. data/lib/marklogic/cursor.rb +238 -0
  19. data/lib/marklogic/database.rb +205 -0
  20. data/lib/marklogic/database_settings.rb +13 -0
  21. data/lib/marklogic/database_settings/element_word_lexicon.rb +28 -0
  22. data/lib/marklogic/database_settings/geospatial_element_child_index.rb +41 -0
  23. data/lib/marklogic/database_settings/geospatial_element_index.rb +38 -0
  24. data/lib/marklogic/database_settings/geospatial_element_pair_index.rb +42 -0
  25. data/lib/marklogic/database_settings/geospatial_path_index.rb +37 -0
  26. data/lib/marklogic/database_settings/index.rb +27 -0
  27. data/lib/marklogic/database_settings/range_element_index.rb +77 -0
  28. data/lib/marklogic/database_settings/range_field_index.rb +37 -0
  29. data/lib/marklogic/database_settings/range_path_index.rb +37 -0
  30. data/lib/marklogic/exceptions.rb +5 -0
  31. data/lib/marklogic/forest.rb +47 -0
  32. data/lib/marklogic/loggable.rb +46 -0
  33. data/lib/marklogic/object_id.rb +46 -0
  34. data/lib/marklogic/persistence.rb +29 -0
  35. data/lib/marklogic/queries.rb +18 -0
  36. data/lib/marklogic/queries/and_not_query.rb +14 -0
  37. data/lib/marklogic/queries/and_query.rb +14 -0
  38. data/lib/marklogic/queries/base_query.rb +40 -0
  39. data/lib/marklogic/queries/boost_query.rb +14 -0
  40. data/lib/marklogic/queries/collection_query.rb +14 -0
  41. data/lib/marklogic/queries/container_query.rb +15 -0
  42. data/lib/marklogic/queries/directory_query.rb +20 -0
  43. data/lib/marklogic/queries/document_fragment_query.rb +13 -0
  44. data/lib/marklogic/queries/document_query.rb +14 -0
  45. data/lib/marklogic/queries/geospatial_query.rb +44 -0
  46. data/lib/marklogic/queries/locks_fragment_query.rb +13 -0
  47. data/lib/marklogic/queries/near_query.rb +31 -0
  48. data/lib/marklogic/queries/not_in_query.rb +14 -0
  49. data/lib/marklogic/queries/not_query.rb +13 -0
  50. data/lib/marklogic/queries/or_query.rb +24 -0
  51. data/lib/marklogic/queries/properties_fragment_query.rb +13 -0
  52. data/lib/marklogic/queries/range_query.rb +67 -0
  53. data/lib/marklogic/queries/value_query.rb +44 -0
  54. data/lib/marklogic/queries/word_query.rb +38 -0
  55. data/lib/marklogic/version.rb +3 -0
  56. data/marklogic.gemspec +23 -0
  57. data/spec/marklogic/app_server_spec.rb +21 -0
  58. data/spec/marklogic/application_spec.rb +105 -0
  59. data/spec/marklogic/collection_spec.rb +154 -0
  60. data/spec/marklogic/connection_spec.rb +128 -0
  61. data/spec/marklogic/cursor_spec.rb +219 -0
  62. data/spec/marklogic/database_settings/element_word_lexicon_spec.rb +21 -0
  63. data/spec/marklogic/database_settings/geospatial_element_child_index_spec.rb +26 -0
  64. data/spec/marklogic/database_settings/geospatial_element_index_spec.rb +24 -0
  65. data/spec/marklogic/database_settings/geospatial_element_pair_index_spec.rb +27 -0
  66. data/spec/marklogic/database_settings/geospatial_path_index_spec.rb +23 -0
  67. data/spec/marklogic/database_settings/range_element_index_spec.rb +34 -0
  68. data/spec/marklogic/database_settings/range_field_index_spec.rb +23 -0
  69. data/spec/marklogic/database_settings/range_path_index_spec.rb +23 -0
  70. data/spec/marklogic/database_spec.rb +108 -0
  71. data/spec/marklogic/forest_spec.rb +30 -0
  72. data/spec/marklogic/queries/and_not_query_spec.rb +13 -0
  73. data/spec/marklogic/queries/and_query_spec.rb +31 -0
  74. data/spec/marklogic/queries/boost_query_spec.rb +13 -0
  75. data/spec/marklogic/queries/collection_query_spec.rb +16 -0
  76. data/spec/marklogic/queries/container_query_spec.rb +11 -0
  77. data/spec/marklogic/queries/directory_query_spec.rb +21 -0
  78. data/spec/marklogic/queries/document_fragment_query_spec.rb +11 -0
  79. data/spec/marklogic/queries/document_query_spec.rb +16 -0
  80. data/spec/marklogic/queries/locks_fragement_query_spec.rb +11 -0
  81. data/spec/marklogic/queries/near_query_spec.rb +62 -0
  82. data/spec/marklogic/queries/not_in_query_spec.rb +13 -0
  83. data/spec/marklogic/queries/not_query_spec.rb +11 -0
  84. data/spec/marklogic/queries/or_query_spec.rb +32 -0
  85. data/spec/marklogic/queries/properties_fragment_query_spec.rb +11 -0
  86. data/spec/marklogic/queries/range_query_spec.rb +71 -0
  87. data/spec/marklogic/queries/value_query_spec.rb +68 -0
  88. data/spec/marklogic/queries/word_query_spec.rb +53 -0
  89. data/spec/spec_helper.rb +68 -0
  90. metadata +186 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ddad5d982939d5693742db6623e91f7d557de379
4
+ data.tar.gz: 77e4174a64065444b8a58408eeddfc3d7d23c879
5
+ SHA512:
6
+ metadata.gz: ba515d4ec20bb8c9f22ff93749d2df9542d5803eb9622d7dea000de4edb6085c90da2a2cd4ecb8f24c0d1c2c2d7efdef62dcd1b56ab9f91bebc3dd5d99d25f30
7
+ data.tar.gz: 162f3f432d888b4ae47357c4345b68069a761b4c6fc14498922ecdbf4138d60c933c2a665602008eaa07a5ea33a9b0fd56dffd6864677f9961e3dd3d0acff16b
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --order random
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ marklogic-gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marklogic.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'guard'
8
+ gem 'rspec'
9
+ gem 'rspec-nc', require: false
10
+
11
+ gem 'pry'
12
+ gem 'pry-byebug'
13
+
14
+ gem 'terminal-notifier-guard', require: false
15
+ gem 'guard-rspec'
16
+ gem 'guard-yard'
17
+ end
data/Guardfile ADDED
@@ -0,0 +1,45 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), then you will want to move
18
+ ## the Guardfile to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ guard 'yard' do
27
+ watch(%r{app/.+\.rb})
28
+ watch(%r{lib/.+\.rb})
29
+ watch(%r{ext/.+\.c})
30
+ end
31
+
32
+ # Note: The cmd option is now required due to the increasing number of ways
33
+ # rspec may be run, below are examples of the most common uses.
34
+ # * bundler: 'bundle exec rspec'
35
+ # * bundler binstubs: 'bin/rspec'
36
+ # * spring: 'bin/rspec' (This will use spring if running and you have
37
+ # installed the spring binstubs per the docs)
38
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
39
+ # * 'just' rspec: 'rspec'
40
+
41
+ guard :rspec, cmd: "bundle exec rspec" do
42
+ watch(%r{^spec/.+_spec\.rb$})
43
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
44
+ watch('spec/spec_helper.rb') { "spec" }
45
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Paxton Hare
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Marklogic
2
+
3
+ A MarkLogic connector for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'marklogic'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install marklogic
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/paxtonhare/marklogic/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
data/lib/marklogic.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/object'
3
+ require 'active_support/core_ext/string/inflections'
4
+ require "marklogic/version"
5
+ require "marklogic/consts"
6
+ require 'marklogic/queries'
7
+ require 'marklogic/exceptions'
8
+ require 'marklogic/object_id'
9
+
10
+ module MarkLogic
11
+ autoload :Application, 'marklogic/application'
12
+ autoload :AppServer, 'marklogic/app_server'
13
+ autoload :Collection, 'marklogic/collection'
14
+ autoload :Connection, 'marklogic/connection'
15
+ autoload :Cursor, 'marklogic/cursor'
16
+ autoload :Database, 'marklogic/database'
17
+ autoload :DatabaseSettings, 'marklogic/database_settings'
18
+ autoload :Forest, 'marklogic/forest'
19
+ autoload :Loggable, 'marklogic/loggable'
20
+ autoload :Persistence, 'marklogic/persistence'
21
+ end
@@ -0,0 +1,60 @@
1
+ module MarkLogic
2
+ class AppServer
3
+ include MarkLogic::Persistence
4
+
5
+ attr_accessor :server_name, :server_type, :group_name
6
+
7
+ def initialize(server_name, port, server_type = "http", group_name = "Default", options = {})
8
+ content_database = options[:content_database] || "#{server_name.gsub(/_/, "-")}-content"
9
+ modules_database = options[:modules_database] || "#{server_name.gsub(/_/, "-")}-modules"
10
+ self.connection = options[:connection]
11
+ self.admin_connection = options[:admin_connection]
12
+
13
+ @server_name = server_name
14
+ @server_type = server_type
15
+ @group_name = group_name
16
+
17
+ @options = {
18
+ "server-name" => @server_name,
19
+ "root" => options[:root] || "/",
20
+ "port" => port,
21
+ "content-database" => content_database,
22
+ "modules-database" => modules_database,
23
+ "url-rewriter" => "/MarkLogic/rest-api/rewriter.xml",
24
+ "error-handler" => "/MarkLogic/rest-api/error-handler.xqy",
25
+ "rewrite-resolves-globally" => true
26
+ }
27
+ end
28
+
29
+ def []=(key, value)
30
+ @options[key] = value
31
+ end
32
+
33
+ def [](key)
34
+ @options[key]
35
+ end
36
+
37
+ def has_key?(key)
38
+ @options.has_key?(key)
39
+ end
40
+
41
+ def create
42
+ r = manage_connection.post_json(
43
+ %Q{/manage/v2/servers/?group-id=#{group_name}&server-type=#{server_type}&format=json},
44
+ @options)
45
+ end
46
+
47
+ def drop
48
+ r = manage_connection.delete(%Q{/manage/v2/servers/#{server_name}?group-id=#{group_name}&format=json})
49
+
50
+ # wait for restart
51
+ admin_connection.wait_for_restart(r.body) if r.code.to_i == 202
52
+
53
+ return r
54
+ end
55
+
56
+ def exists?
57
+ manage_connection.head(%Q{/manage/v2/servers/#{server_name}?group-id=#{group_name}}).code.to_i == 200
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,244 @@
1
+ module MarkLogic
2
+ class Application
3
+ include MarkLogic::Persistence
4
+
5
+ attr_accessor :app_name
6
+
7
+ def initialize(app_name, options = {})
8
+ @app_name = app_name
9
+ self.connection = options[:connection]
10
+ @port = options[:port] || self.connection.port
11
+ self.admin_connection = options[:admin_connection]
12
+ end
13
+
14
+ def create
15
+ logger.debug(%Q{Creating Application: #{@app_name}})
16
+
17
+ build_implicit_defs
18
+
19
+ databases.each do |database_name, database|
20
+ unless database.exists?
21
+ database.create
22
+ else
23
+ database.update
24
+ end
25
+ end
26
+
27
+ forests.each do |forest_name, forest|
28
+ forest.create unless forest.exists?
29
+ end
30
+
31
+ app_servers.each do |server_name, app_server|
32
+ app_server.create unless app_server.exists?
33
+ end
34
+
35
+ end
36
+
37
+ def create_indexes
38
+ build_implicit_defs
39
+
40
+ content_databases.each do |database|
41
+ if database.exists?
42
+ database.update
43
+ else
44
+ database.create
45
+ end
46
+ end
47
+ end
48
+
49
+ def sync
50
+ create if stale?
51
+ end
52
+
53
+ def sync!
54
+ create
55
+ end
56
+
57
+ def drop
58
+ logger.debug(%Q{Dropping Application: #{@app_name}})
59
+
60
+ build_implicit_defs
61
+
62
+ app_servers.each do |server_name, app_server|
63
+ app_server.drop if app_server.exists?
64
+ end
65
+
66
+ databases.each do |database_name, database|
67
+ if database.exists?
68
+ database.drop
69
+ end
70
+ end
71
+
72
+ forests.each do |forest_name, forest|
73
+ if forest.exists?
74
+ forest.drop
75
+ end
76
+ end
77
+ end
78
+
79
+ def exists?
80
+ build_implicit_defs
81
+
82
+ databases.each do |database_name, database|
83
+ return false if !database.exists?
84
+ end
85
+
86
+ forests.each do |forest_name, forest|
87
+ return false if !forest.exists?
88
+ end
89
+
90
+ app_servers.each do |server_name, app_server|
91
+ return false if !app_server.exists?
92
+ end
93
+
94
+ return true
95
+ end
96
+
97
+ def stale?
98
+ build_implicit_defs
99
+
100
+ databases.each do |database_name, database|
101
+ unless database.exists?
102
+ logger.debug "database: #{database_name} is missing"
103
+ return true
104
+ end
105
+ end
106
+
107
+ content_databases.each do |database|
108
+ if database.stale?
109
+ logger.debug "database: #{database.database_name} is stale"
110
+ return true
111
+ end
112
+ end
113
+
114
+ forests.each do |forest_name, forest|
115
+ unless forest.exists?
116
+ logger.debug "forest: #{forest_name} is missing"
117
+ return true
118
+ end
119
+ end
120
+
121
+ app_servers.each do |server_name, app_server|
122
+ unless app_server.exists?
123
+ logger.debug "app_server: #{server_name} is missing"
124
+ return true
125
+ end
126
+ end
127
+
128
+ return false
129
+ end
130
+
131
+ def forests
132
+ @forests ||= {}
133
+ end
134
+
135
+ def databases
136
+ @databases ||= {}
137
+ end
138
+
139
+ def app_servers
140
+ @app_servers ||= {}
141
+ end
142
+
143
+ def add_index(index)
144
+ indexes[index.key] = index
145
+ end
146
+
147
+ def clear_indexes()
148
+ content_databases.each do |database|
149
+ database.reset_indexes
150
+ end
151
+ @indexes = {}
152
+ end
153
+
154
+ def content_databases
155
+ app_servers.values.map do |app_server|
156
+ databases[app_server['content-database']]
157
+ end
158
+ end
159
+
160
+ def database(name)
161
+ database = MarkLogic::Database.new(name)
162
+ yield(database) if block_given?
163
+ logger.info("#{__LINE__}: db_name: #{name}")
164
+ databases[name] = database
165
+ end
166
+
167
+ def app_server(name)
168
+ app_server = MarkLogic::AppServer.new(name, @port)
169
+ yield(app_server) if block_given?
170
+ app_servers[name] = app_server
171
+ end
172
+
173
+ private
174
+
175
+ def indexes
176
+ @indexes ||= {}
177
+ end
178
+
179
+ def build_implicit_defs
180
+ build_appservers
181
+ build_databases
182
+ build_indexes
183
+ end
184
+
185
+ def build_appservers
186
+ if app_servers.empty?
187
+ app_servers[@app_name] = MarkLogic::AppServer.new(@app_name, @port, "http", "Default", :connection => self.connection, :admin_connection => admin_connection)
188
+ end
189
+ end
190
+
191
+ def build_databases
192
+ app_servers.each_value do |app_server|
193
+ db_name = app_server['content-database']
194
+ unless databases.has_key?(db_name)
195
+ db = MarkLogic::Database.new(db_name, self.connection)
196
+ db.application = self
197
+ databases[db_name] = db
198
+ end
199
+ forests[db_name] = MarkLogic::Forest.new(db_name, nil, self.connection) unless forests.has_key?(db_name)
200
+ forests[db_name].database = databases[db_name]
201
+
202
+ modules_db_name = app_server['modules-database']
203
+ unless databases.has_key?(modules_db_name)
204
+ modules_db = MarkLogic::Database.new(modules_db_name, self.connection)
205
+ modules_db.application = self
206
+ databases[modules_db_name] = modules_db
207
+ end
208
+ forests[modules_db_name] = MarkLogic::Forest.new(modules_db_name, nil, self.connection) unless forests.has_key?(modules_db_name)
209
+ forests[modules_db_name].database = databases[modules_db_name]
210
+ end
211
+
212
+ triggers_database = nil
213
+ schema_database = nil
214
+ databases.each_value do |database|
215
+ if database.has_key?('triggers-database')
216
+ logger.info "has triggers: [#{database['triggers-database']}]"
217
+ triggers_database = database['triggers-database']
218
+ end
219
+
220
+ if database.has_key?('schema-database')
221
+ schema_database = database['schema-database']
222
+ end
223
+ end
224
+
225
+ if triggers_database and !databases.has_key?(triggers_database)
226
+ databases[triggers_database] = MarkLogic::Database.new(triggers_database, self.connection)
227
+ end
228
+
229
+ if schema_database and !databases.has_key?(schema_database)
230
+ databases[schema_database] = MarkLogic::Database.new(schema_database, self.connection)
231
+ end
232
+ end
233
+
234
+ def build_indexes
235
+ content_databases.each do |database|
236
+ database.reset_indexes
237
+
238
+ indexes.clone.each do |key, index|
239
+ index.append_to_db(database)
240
+ end
241
+ end
242
+ end
243
+ end
244
+ end