mark_mapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.rdoc +39 -0
  4. data/examples/attr_accessible.rb +24 -0
  5. data/examples/attr_protected.rb +24 -0
  6. data/examples/cache_key.rb +26 -0
  7. data/examples/custom_types.rb +26 -0
  8. data/examples/identity_map.rb +30 -0
  9. data/examples/identity_map/automatic.rb +2 -0
  10. data/examples/keys.rb +42 -0
  11. data/examples/modifiers/set.rb +27 -0
  12. data/examples/plugins.rb +40 -0
  13. data/examples/querying.rb +39 -0
  14. data/examples/sample_app.rb +43 -0
  15. data/examples/scopes.rb +56 -0
  16. data/examples/validating/embedded_docs.rb +31 -0
  17. data/lib/mark_mapper.rb +125 -0
  18. data/lib/mark_mapper/config.rb +90 -0
  19. data/lib/mark_mapper/connection.rb +60 -0
  20. data/lib/mark_mapper/criteria_hash.rb +194 -0
  21. data/lib/mark_mapper/document.rb +46 -0
  22. data/lib/mark_mapper/embedded_document.rb +32 -0
  23. data/lib/mark_mapper/exceptions.rb +33 -0
  24. data/lib/mark_mapper/extensions/array.rb +27 -0
  25. data/lib/mark_mapper/extensions/boolean.rb +45 -0
  26. data/lib/mark_mapper/extensions/date.rb +29 -0
  27. data/lib/mark_mapper/extensions/duplicable.rb +86 -0
  28. data/lib/mark_mapper/extensions/float.rb +18 -0
  29. data/lib/mark_mapper/extensions/hash.rb +26 -0
  30. data/lib/mark_mapper/extensions/integer.rb +27 -0
  31. data/lib/mark_mapper/extensions/kernel.rb +11 -0
  32. data/lib/mark_mapper/extensions/nil_class.rb +18 -0
  33. data/lib/mark_mapper/extensions/object.rb +30 -0
  34. data/lib/mark_mapper/extensions/object_id.rb +18 -0
  35. data/lib/mark_mapper/extensions/set.rb +20 -0
  36. data/lib/mark_mapper/extensions/string.rb +31 -0
  37. data/lib/mark_mapper/extensions/symbol.rb +87 -0
  38. data/lib/mark_mapper/extensions/time.rb +29 -0
  39. data/lib/mark_mapper/locale/en.yml +5 -0
  40. data/lib/mark_mapper/middleware/identity_map.rb +41 -0
  41. data/lib/mark_mapper/normalizers/criteria_hash_key.rb +17 -0
  42. data/lib/mark_mapper/normalizers/criteria_hash_value.rb +66 -0
  43. data/lib/mark_mapper/normalizers/fields_value.rb +26 -0
  44. data/lib/mark_mapper/normalizers/hash_key.rb +19 -0
  45. data/lib/mark_mapper/normalizers/integer.rb +19 -0
  46. data/lib/mark_mapper/normalizers/options_hash_value.rb +83 -0
  47. data/lib/mark_mapper/normalizers/sort_value.rb +55 -0
  48. data/lib/mark_mapper/options_hash.rb +103 -0
  49. data/lib/mark_mapper/pagination.rb +6 -0
  50. data/lib/mark_mapper/pagination/collection.rb +32 -0
  51. data/lib/mark_mapper/pagination/paginator.rb +46 -0
  52. data/lib/mark_mapper/plugins.rb +22 -0
  53. data/lib/mark_mapper/plugins/accessible.rb +61 -0
  54. data/lib/mark_mapper/plugins/active_model.rb +18 -0
  55. data/lib/mark_mapper/plugins/associations.rb +96 -0
  56. data/lib/mark_mapper/plugins/associations/base.rb +98 -0
  57. data/lib/mark_mapper/plugins/associations/belongs_to_association.rb +63 -0
  58. data/lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +35 -0
  59. data/lib/mark_mapper/plugins/associations/belongs_to_proxy.rb +52 -0
  60. data/lib/mark_mapper/plugins/associations/collection.rb +29 -0
  61. data/lib/mark_mapper/plugins/associations/embedded_collection.rb +44 -0
  62. data/lib/mark_mapper/plugins/associations/in_array_proxy.rb +133 -0
  63. data/lib/mark_mapper/plugins/associations/many_association.rb +63 -0
  64. data/lib/mark_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
  65. data/lib/mark_mapper/plugins/associations/many_documents_proxy.rb +142 -0
  66. data/lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -0
  67. data/lib/mark_mapper/plugins/associations/many_embedded_proxy.rb +24 -0
  68. data/lib/mark_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -0
  69. data/lib/mark_mapper/plugins/associations/one_as_proxy.rb +22 -0
  70. data/lib/mark_mapper/plugins/associations/one_association.rb +48 -0
  71. data/lib/mark_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +30 -0
  72. data/lib/mark_mapper/plugins/associations/one_embedded_proxy.rb +44 -0
  73. data/lib/mark_mapper/plugins/associations/one_proxy.rb +95 -0
  74. data/lib/mark_mapper/plugins/associations/proxy.rb +138 -0
  75. data/lib/mark_mapper/plugins/associations/single_association.rb +46 -0
  76. data/lib/mark_mapper/plugins/caching.rb +21 -0
  77. data/lib/mark_mapper/plugins/callbacks.rb +42 -0
  78. data/lib/mark_mapper/plugins/clone.rb +24 -0
  79. data/lib/mark_mapper/plugins/counter_cache.rb +97 -0
  80. data/lib/mark_mapper/plugins/dirty.rb +61 -0
  81. data/lib/mark_mapper/plugins/document.rb +41 -0
  82. data/lib/mark_mapper/plugins/dumpable.rb +22 -0
  83. data/lib/mark_mapper/plugins/dynamic_querying.rb +45 -0
  84. data/lib/mark_mapper/plugins/dynamic_querying/dynamic_finder.rb +44 -0
  85. data/lib/mark_mapper/plugins/embedded_callbacks.rb +81 -0
  86. data/lib/mark_mapper/plugins/embedded_document.rb +53 -0
  87. data/lib/mark_mapper/plugins/equality.rb +23 -0
  88. data/lib/mark_mapper/plugins/identity_map.rb +144 -0
  89. data/lib/mark_mapper/plugins/indexable.rb +86 -0
  90. data/lib/mark_mapper/plugins/inspect.rb +16 -0
  91. data/lib/mark_mapper/plugins/keys.rb +470 -0
  92. data/lib/mark_mapper/plugins/keys/key.rb +134 -0
  93. data/lib/mark_mapper/plugins/keys/static.rb +45 -0
  94. data/lib/mark_mapper/plugins/logger.rb +18 -0
  95. data/lib/mark_mapper/plugins/modifiers.rb +140 -0
  96. data/lib/mark_mapper/plugins/pagination.rb +16 -0
  97. data/lib/mark_mapper/plugins/partial_updates.rb +77 -0
  98. data/lib/mark_mapper/plugins/persistence.rb +79 -0
  99. data/lib/mark_mapper/plugins/protected.rb +45 -0
  100. data/lib/mark_mapper/plugins/querying.rb +173 -0
  101. data/lib/mark_mapper/plugins/querying/decorated_markmapper_query.rb +75 -0
  102. data/lib/mark_mapper/plugins/rails.rb +79 -0
  103. data/lib/mark_mapper/plugins/rails/active_record_association_adapter.rb +33 -0
  104. data/lib/mark_mapper/plugins/sci.rb +82 -0
  105. data/lib/mark_mapper/plugins/scopes.rb +28 -0
  106. data/lib/mark_mapper/plugins/serialization.rb +109 -0
  107. data/lib/mark_mapper/plugins/timestamps.rb +29 -0
  108. data/lib/mark_mapper/plugins/touch.rb +18 -0
  109. data/lib/mark_mapper/plugins/userstamps.rb +18 -0
  110. data/lib/mark_mapper/plugins/validations.rb +96 -0
  111. data/lib/mark_mapper/query.rb +278 -0
  112. data/lib/mark_mapper/railtie.rb +52 -0
  113. data/lib/mark_mapper/railtie/database.rake +65 -0
  114. data/lib/mark_mapper/translation.rb +10 -0
  115. data/lib/mark_mapper/version.rb +4 -0
  116. data/lib/rails/generators/mark_mapper/config/config_generator.rb +37 -0
  117. data/lib/rails/generators/mark_mapper/config/templates/marklogic.yml +19 -0
  118. data/lib/rails/generators/mark_mapper/model/model_generator.rb +40 -0
  119. data/lib/rails/generators/mark_mapper/model/templates/model.rb +17 -0
  120. data/spec/config/mark_mapper.yml +6 -0
  121. data/spec/examples_spec.rb +25 -0
  122. data/spec/functional/accessible_spec.rb +198 -0
  123. data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +64 -0
  124. data/spec/functional/associations/belongs_to_proxy_spec.rb +255 -0
  125. data/spec/functional/associations/in_array_proxy_spec.rb +349 -0
  126. data/spec/functional/associations/many_documents_as_proxy_spec.rb +230 -0
  127. data/spec/functional/associations/many_documents_proxy_spec.rb +968 -0
  128. data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +238 -0
  129. data/spec/functional/associations/many_embedded_proxy_spec.rb +288 -0
  130. data/spec/functional/associations/many_polymorphic_proxy_spec.rb +302 -0
  131. data/spec/functional/associations/one_as_proxy_spec.rb +489 -0
  132. data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +207 -0
  133. data/spec/functional/associations/one_embedded_proxy_spec.rb +100 -0
  134. data/spec/functional/associations/one_proxy_spec.rb +406 -0
  135. data/spec/functional/associations_spec.rb +48 -0
  136. data/spec/functional/caching_spec.rb +75 -0
  137. data/spec/functional/callbacks_spec.rb +330 -0
  138. data/spec/functional/counter_cache_spec.rb +235 -0
  139. data/spec/functional/dirty_spec.rb +316 -0
  140. data/spec/functional/document_spec.rb +310 -0
  141. data/spec/functional/dumpable_spec.rb +24 -0
  142. data/spec/functional/dynamic_querying_spec.rb +75 -0
  143. data/spec/functional/embedded_document_spec.rb +316 -0
  144. data/spec/functional/equality_spec.rb +20 -0
  145. data/spec/functional/extensions_spec.rb +16 -0
  146. data/spec/functional/identity_map_spec.rb +483 -0
  147. data/spec/functional/keys_spec.rb +339 -0
  148. data/spec/functional/logger_spec.rb +20 -0
  149. data/spec/functional/modifiers_spec.rb +446 -0
  150. data/spec/functional/options_hash_spec.rb +41 -0
  151. data/spec/functional/pagination_spec.rb +89 -0
  152. data/spec/functional/partial_updates_spec.rb +530 -0
  153. data/spec/functional/protected_spec.rb +199 -0
  154. data/spec/functional/querying_spec.rb +984 -0
  155. data/spec/functional/rails_spec.rb +55 -0
  156. data/spec/functional/sci_spec.rb +374 -0
  157. data/spec/functional/scopes_spec.rb +204 -0
  158. data/spec/functional/static_keys_spec.rb +153 -0
  159. data/spec/functional/timestamps_spec.rb +97 -0
  160. data/spec/functional/touch_spec.rb +125 -0
  161. data/spec/functional/userstamps_spec.rb +46 -0
  162. data/spec/functional/validations_spec.rb +416 -0
  163. data/spec/quality_spec.rb +51 -0
  164. data/spec/spec_helper.rb +150 -0
  165. data/spec/support/matchers.rb +15 -0
  166. data/spec/support/models.rb +256 -0
  167. data/spec/symbol_operator_spec.rb +70 -0
  168. data/spec/symbol_spec.rb +9 -0
  169. data/spec/unit/associations/base_spec.rb +146 -0
  170. data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
  171. data/spec/unit/associations/many_association_spec.rb +64 -0
  172. data/spec/unit/associations/one_association_spec.rb +48 -0
  173. data/spec/unit/associations/proxy_spec.rb +103 -0
  174. data/spec/unit/clone_spec.rb +79 -0
  175. data/spec/unit/config_generator_spec.rb +24 -0
  176. data/spec/unit/criteria_hash_spec.rb +218 -0
  177. data/spec/unit/document_spec.rb +251 -0
  178. data/spec/unit/dynamic_finder_spec.rb +125 -0
  179. data/spec/unit/embedded_document_spec.rb +676 -0
  180. data/spec/unit/equality_spec.rb +38 -0
  181. data/spec/unit/exceptions_spec.rb +12 -0
  182. data/spec/unit/extensions_spec.rb +368 -0
  183. data/spec/unit/identity_map_middleware_spec.rb +134 -0
  184. data/spec/unit/inspect_spec.rb +47 -0
  185. data/spec/unit/key_spec.rb +276 -0
  186. data/spec/unit/keys_spec.rb +155 -0
  187. data/spec/unit/mark_mapper_spec.rb +37 -0
  188. data/spec/unit/model_generator_spec.rb +45 -0
  189. data/spec/unit/normalizers/criteria_hash_key_spec.rb +37 -0
  190. data/spec/unit/normalizers/criteria_hash_value_spec.rb +200 -0
  191. data/spec/unit/normalizers/fields_value_spec.rb +45 -0
  192. data/spec/unit/normalizers/hash_key_spec.rb +15 -0
  193. data/spec/unit/normalizers/integer_spec.rb +24 -0
  194. data/spec/unit/normalizers/options_hash_value_spec.rb +99 -0
  195. data/spec/unit/normalizers/sort_value_spec.rb +98 -0
  196. data/spec/unit/options_hash_spec.rb +64 -0
  197. data/spec/unit/pagination/collection_spec.rb +30 -0
  198. data/spec/unit/pagination/paginator_spec.rb +118 -0
  199. data/spec/unit/pagination_spec.rb +11 -0
  200. data/spec/unit/plugins_spec.rb +89 -0
  201. data/spec/unit/query_spec.rb +837 -0
  202. data/spec/unit/rails_compatibility_spec.rb +40 -0
  203. data/spec/unit/rails_reflect_on_association_spec.rb +118 -0
  204. data/spec/unit/rails_spec.rb +188 -0
  205. data/spec/unit/serialization_spec.rb +169 -0
  206. data/spec/unit/serializers/json_serializer_spec.rb +218 -0
  207. data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
  208. data/spec/unit/time_zones_spec.rb +44 -0
  209. data/spec/unit/translation_spec.rb +27 -0
  210. data/spec/unit/validations_spec.rb +588 -0
  211. metadata +307 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8da86f713512ffdee54852951d9e1e2f94c0bf5
4
+ data.tar.gz: 768ad651bee67d55396095b14db35963387fa9bc
5
+ SHA512:
6
+ metadata.gz: b78ac1946be9798b7b53f6299d2164cafd6b941b603584b1aa5ce720ce9139ffe85c5ca7ee00a30b41c00d292b4327b44f01e504ceb9f4c2b383e787446a1715
7
+ data.tar.gz: 5dfb0ecac9c51de0b446d7466d56e7baedd97fe84f79102126aa21b6938fc194dc3c11fed2023a78749672abc3b473ee5a61750b20f30f037c929874948b084f
data/LICENSE 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.rdoc ADDED
@@ -0,0 +1,39 @@
1
+ = MarkMapper
2
+
3
+ A Ruby Object Mapper for MarkLogic.
4
+
5
+ == Install
6
+
7
+ $ gem install mark_mapper
8
+
9
+ == Documentation
10
+
11
+ http://markmapper.com/documentation/
12
+
13
+ http://rdoc.info/github/markmapper/markmapper
14
+
15
+ == Compatibility
16
+
17
+ MarkMapper is tested against:
18
+
19
+ * MRI 2.2.0
20
+
21
+ Additionally, MarkMapper is tested against:
22
+
23
+ * Rails 4.2.x
24
+
25
+ == Contributing & Development
26
+
27
+ $ git clone https://github.com/paxtonhare/markmapper && cd markmapper
28
+ $ bundle install
29
+ $ bundle exec rake
30
+
31
+ * Fork the project.
32
+ * Make your feature addition or bug fix. All specs should pass.
33
+ * Add specs for your changes. This is important so I don't break it in a future version unintentionally.
34
+ * Commit, do not mess with Rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself in another branch so a maintainer ignore it when your pull request is merged.
35
+ * Send a pull request. Bonus points for topic branches.
36
+
37
+ == License & Copyright
38
+
39
+ See LICENSE for details.
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+
4
+ MarkMapper.application.create
5
+
6
+ class User
7
+ include MarkMapper::Document
8
+ key :email, String
9
+ key :admin, Boolean, :default => false
10
+
11
+ # Only accessible or protected can be used, they cannot be used together
12
+ attr_accessible :email
13
+ end
14
+
15
+ # only accessible are set on new/create/etc.
16
+ user = User.create(:email => 'IDontLowerCaseThings@gmail.com', :admin => true)
17
+ puts user.admin # false
18
+
19
+ # can be set using accessor
20
+ user.admin = true
21
+ user.save
22
+ puts user.admin # true
23
+
24
+ MarkMapper.application.drop
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+
4
+ MarkMapper.application.create
5
+
6
+ class User
7
+ include MarkMapper::Document
8
+ key :email, String
9
+ key :admin, Boolean, :default => false
10
+
11
+ # Only accessible or protected can be used, they cannot be used together
12
+ attr_protected :admin
13
+ end
14
+
15
+ # protected are ignored on new/create/etc.
16
+ user = User.create(:email => 'IDontLowerCaseThings@gmail.com', :admin => true)
17
+ puts user.admin # false
18
+
19
+ # can be set using accessor
20
+ user.admin = true
21
+ user.save
22
+ puts user.admin # true
23
+
24
+ MarkMapper.application.drop
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+
4
+ MarkMapper.application.create
5
+
6
+ class User
7
+ include MarkMapper::Document
8
+ end
9
+
10
+ # New Documents
11
+ puts User.new.cache_key # User/new
12
+
13
+ # Created Documents
14
+ puts User.create.cache_key # User/:id (ie: User/4c7a940cbcd1b3319b000003)
15
+
16
+ # With Suffix
17
+ puts User.create.cache_key(:foo) # User/:id/foo
18
+
19
+ # With Multiple Suffixes
20
+ puts User.create.cache_key(:foo, :bar, :baz) # User/:id/foo/bar/baz
21
+
22
+ # When updated_at key exists it will be used
23
+ User.timestamps!
24
+ puts User.create.cache_key # User/:id-:updated_at (ie: User/4c7a940cbcd1b3319b000003-20100829170828)
25
+
26
+ MarkMapper.application.drop
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+ require 'pp'
4
+
5
+ MarkMapper.application.create
6
+
7
+ class DowncasedString
8
+ # to_marklogic gets called anytime a value is assigned
9
+ def self.to_marklogic(value)
10
+ value.nil? ? nil : value.to_s.downcase
11
+ end
12
+
13
+ # from marklogic gets called anytime a value is read
14
+ def self.from_marklogic(value)
15
+ value.nil? ? nil : value.to_s.downcase
16
+ end
17
+ end
18
+
19
+ class User
20
+ include MarkMapper::Document
21
+ key :email, DowncasedString
22
+ end
23
+
24
+ pp User.create(:email => 'IDontLowerCaseThings@gmail.com')
25
+
26
+ MarkMapper.application.drop
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+ require 'pp'
4
+
5
+ MarkMapper.application.create
6
+
7
+ MarkMapper::Plugins::IdentityMap.enabled = true
8
+
9
+ class User
10
+ include MarkMapper::Document
11
+
12
+ key :name, String
13
+ end
14
+ User.delete_all
15
+
16
+ # User gets added to map on save
17
+ user = User.create(:name => 'John')
18
+
19
+ # Does not matter how you find user, it is always the same object until the identity map is cleared
20
+ puts "#{User.find(user.id).object_id} == #{user.object_id}"
21
+ puts "#{User.all[0].object_id} == #{user.object_id}"
22
+
23
+ MarkMapper::Plugins::IdentityMap.clear
24
+ puts "#{User.find(user.id).object_id} != #{user.object_id}"
25
+
26
+ # User gets removed from map on destroy
27
+ user = User.create
28
+ user.destroy
29
+
30
+ MarkMapper.application.drop
@@ -0,0 +1,2 @@
1
+ # Using the following will turn on identity map for all models
2
+ MarkMapper::Plugins::IdentityMap.enabled = true
data/examples/keys.rb ADDED
@@ -0,0 +1,42 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+ require 'pp'
4
+
5
+ MarkMapper.application.create
6
+
7
+ class User
8
+ include MarkMapper::Document
9
+
10
+ key :first_name, String, :required => true
11
+ key :last_name, String, :required => true
12
+ key :token, String, :default => lambda { 'some random string' }
13
+ key :age, Integer
14
+ key :skills, Array
15
+ key :friend_ids, Array, :typecast => 'ObjectId'
16
+ key :links, Hash
17
+ timestamps!
18
+ end
19
+ User.collection.remove # empties collection
20
+
21
+ john = User.create({
22
+ :first_name => 'John',
23
+ :last_name => 'Nunemaker',
24
+ :age => 28,
25
+ :skills => ['ruby', 'marklogic', 'javascript'],
26
+ :links => {"Google" => "http://www.google.com"}
27
+ })
28
+
29
+ steve = User.create({
30
+ :first_name => 'Steve',
31
+ :last_name => 'Smith',
32
+ :age => 29,
33
+ :skills => ['html', 'css', 'javascript', 'design'],
34
+ })
35
+
36
+ john.friend_ids << steve.id.to_s # will get typecast to ObjectId
37
+ john.links["Ruby on Rails"] = "http://www.rubyonrails.com"
38
+ john.save
39
+
40
+ pp john
41
+
42
+ MarkMapper.application.drop
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
2
+ require_relative '../sample_app'
3
+ require 'pp'
4
+
5
+ MarkMapper.application.create
6
+
7
+ class User
8
+ include MarkMapper::Document
9
+
10
+ key :name, String
11
+ key :tags, Array
12
+ end
13
+ User.collection.remove # empties collection
14
+
15
+ john = User.create(:name => 'John', :tags => %w[ruby marklogic], :age => 28)
16
+ bill = User.create(:name => 'Bill', :tags => %w[ruby marklogic], :age => 30)
17
+
18
+ User.set({:name => 'John'}, :tags => %[ruby])
19
+ pp john.reload
20
+
21
+ User.set(john.id, :tags => %w[ruby marklogic])
22
+ pp john.reload
23
+
24
+ john.set(:tags => %w[something different])
25
+ pp john.reload
26
+
27
+ MarkMapper.application.drop
@@ -0,0 +1,40 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+ require 'pp'
4
+
5
+ MarkMapper.application.create
6
+
7
+ # To create your own plugin, just create a module that
8
+ # extends ActiveSupport::Concern.
9
+ module FooPlugin
10
+ extend ActiveSupport::Concern
11
+
12
+ # ClassMethods module will automatically get extended
13
+ module ClassMethods
14
+ def foo
15
+ 'Foo class method!'
16
+ end
17
+ end
18
+
19
+ def foo
20
+ 'Foo instance method!'
21
+ end
22
+
23
+ # Any configuration can be done in the #included block, which gets
24
+ # class evaled. Feel free to add keys, validations, or anything else.
25
+ included do
26
+ puts "Configuring #{self}..."
27
+ key :foo, String
28
+ end
29
+ end
30
+
31
+ class User
32
+ include MarkMapper::Document
33
+ plugin FooPlugin
34
+ end
35
+
36
+ puts User.foo
37
+ puts User.new.foo
38
+ puts User.key?(:foo)
39
+
40
+ MarkMapper.application.drop
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+ require 'pp'
4
+
5
+ MarkMapper.application.tap do |app|
6
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:age, :type => 'int'))
7
+ end.sync
8
+
9
+ class User
10
+ include MarkMapper::Document
11
+
12
+ key :name, String
13
+ key :tags, Array
14
+ end
15
+ User.collection.remove # empties collection
16
+
17
+ User.create(:name => 'John', :tags => %w[ruby marklogic], :age => 28)
18
+ User.create(:name => 'Bill', :tags => %w[ruby marklogic], :age => 30)
19
+ User.create(:name => 'Frank', :tags => %w[marklogic], :age => 35)
20
+ User.create(:name => 'Steve', :tags => %w[html5 css3], :age => 27)
21
+
22
+ [
23
+
24
+ User.all(:name => 'John'),
25
+ User.all(:tags => %w[marklogic]),
26
+ # User.all(:tags.all => %w[ruby marklogic]),
27
+ User.all(:age.ge => 30),
28
+
29
+ User.where(:age.gt => 27).sort(:age).all,
30
+ User.where(:age.gt => 27).sort(:age.desc).all,
31
+ User.where(:age.gt => 27).sort(:age).limit(1).all,
32
+ User.where(:age.gt => 27).sort(:age).skip(1).limit(1).all,
33
+
34
+ ].each do |result|
35
+ pp result
36
+ puts
37
+ end
38
+
39
+ MarkMapper.application.drop
@@ -0,0 +1,43 @@
1
+ require 'marklogic'
2
+ require 'mark_mapper'
3
+
4
+ # These environment variables can be set if wanting to test against a database
5
+ # that is not on the local machine.
6
+ ENV["MARKMAPPER_SPEC_HOST"] ||= "localhost"
7
+ ENV["MARKMAPPER_SPEC_PORT"] ||= "8009"
8
+
9
+ ENV["MARKMAPPER_SPEC_APP_SERVICES_PORT"] ||= "8000"
10
+ ENV["MARKMAPPER_SPEC_ADMIN_PORT"] ||= "8001"
11
+ ENV["MARKMAPPER_SPEC_MANAGE_PORT"] ||= "8002"
12
+
13
+ ENV["MARKMAPPER_SPEC_USER"] ||= "admin"
14
+ ENV["MARKMAPPER_SPEC_PASSWORD"] ||= "admin"
15
+ ENV["MARKMAPPER_SKIP_APP_CREATION"] ||= "false"
16
+
17
+ # These are used when creating any connection in the test suite.
18
+ HOST = ENV["MARKMAPPER_SPEC_HOST"]
19
+ PORT = ENV["MARKMAPPER_SPEC_PORT"].to_i
20
+
21
+ APP_SERVICES_PORT = ENV["MARKMAPPER_SPEC_APP_SERVICES_PORT"]
22
+ MANAGE_PORT = ENV["MARKMAPPER_SPEC_MANAGE_PORT"]
23
+ ADMIN_PORT = ENV["MARKMAPPER_SPEC_ADMIN_PORT"]
24
+
25
+ USER = ENV["MARKMAPPER_SPEC_USER"]
26
+ PASSWORD = ENV["MARKMAPPER_SPEC_PASSWORD"]
27
+
28
+ ADMIN_USER = ENV["MARKMAPPER_SPEC_ADMIN_USER"]
29
+ ADMIN_PASSWORD = ENV["MARKMAPPER_SPEC_ADMIN_PASSWORD"]
30
+
31
+ MarkLogic::Connection.configure({
32
+ :host => HOST,
33
+ :manage_port => MANAGE_PORT,
34
+ :admin_port => ADMIN_PORT,
35
+ :app_services_port => APP_SERVICES_PORT,
36
+ :default_user => ADMIN_USER,
37
+ :default_password => ADMIN_PASSWORD
38
+ })
39
+
40
+ CONNECTION = MarkLogic::Connection.new(HOST, PORT)
41
+
42
+ puts "Configuring application again"
43
+ MarkMapper.application = MarkLogic::Application.new("sample-app", connection: CONNECTION )
@@ -0,0 +1,56 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require_relative './sample_app'
3
+ require 'pp'
4
+
5
+ MarkMapper.application.tap do |app|
6
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:age, :type => 'int'))
7
+ end.sync
8
+
9
+ class User
10
+ include MarkMapper::Document
11
+
12
+ # plain old vanilla scopes with fancy queries
13
+ scope :johns, where(:name => 'John')
14
+
15
+ # plain old vanilla scopes with hashes
16
+ scope :bills, :name => 'Bill'
17
+
18
+ # dynamic scopes with parameters
19
+ scope :by_name, lambda { |name| where(:name => name) }
20
+ scope :by_ages, lambda { |low, high| where(:age.ge => low, :age.le => high) }
21
+
22
+ # Yep, even plain old methods work as long as they return a query
23
+ def self.by_tag(tag)
24
+ where(:tags => tag)
25
+ end
26
+
27
+ # You can even make a method that returns a scope
28
+ def self.twenties; by_ages(20, 29) end
29
+
30
+ key :name, String
31
+ key :tags, Array
32
+ end
33
+ User.collection.remove # empties collection
34
+
35
+ User.create(:name => 'John', :tags => %w[ruby marklogic], :age => 28)
36
+ User.create(:name => 'Bill', :tags => %w[ruby marklogic], :age => 30)
37
+ User.create(:name => 'Frank', :tags => %w[marklogic], :age => 35)
38
+ User.create(:name => 'Steve', :tags => %w[html5 css3], :age => 27)
39
+
40
+ # simple scopes
41
+ pp User.johns.first
42
+ pp User.bills.first
43
+
44
+ # scope with arg
45
+ pp User.by_name('Frank').first
46
+
47
+ # scope with two args
48
+ pp User.by_ages(20, 29).all
49
+
50
+ # chaining class methods on scopes
51
+ pp User.by_ages(20, 40).by_tag('ruby').all
52
+
53
+ # scope made using method that returns scope
54
+ pp User.twenties.all
55
+
56
+ MarkMapper.application.drop