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
@@ -0,0 +1,51 @@
1
+ # if defined?(Encoding) && Encoding.default_external != "UTF-8"
2
+ # Encoding.default_external = "UTF-8"
3
+ # end
4
+
5
+ # describe "The library itself" do
6
+ # def check_for_tab_characters(filename)
7
+ # failing_lines = []
8
+ # File.readlines(filename).each_with_index do |line,number|
9
+ # failing_lines << number + 1 if line =~ /\t/
10
+ # end
11
+
12
+ # unless failing_lines.empty?
13
+ # "#{filename} has tab characters on lines #{failing_lines.join(', ')}"
14
+ # end
15
+ # end
16
+
17
+ # def check_for_extra_spaces(filename)
18
+ # failing_lines = []
19
+ # File.readlines(filename).each_with_index do |line,number|
20
+ # next if line =~ /^\s+#.*\s+\n$/
21
+ # failing_lines << number + 1 if line =~ /\s+\n$/
22
+ # end
23
+
24
+ # unless failing_lines.empty?
25
+ # "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
26
+ # end
27
+ # end
28
+
29
+ # RSpec::Matchers.define :be_well_formed do
30
+ # failure_message do |actual|
31
+ # actual.join("\n")
32
+ # end
33
+
34
+ # match do |actual|
35
+ # actual.empty?
36
+ # end
37
+ # end
38
+
39
+ # it "has no malformed whitespace" do
40
+ # exempt = /\.gitmodules|\.marshal|fixtures|vendor|ssl_certs|kill|LICENSE/
41
+ # error_messages = []
42
+ # Dir.chdir(File.expand_path("../..", __FILE__)) do
43
+ # `git ls-files`.split("\n").each do |filename|
44
+ # next if filename =~ exempt
45
+ # error_messages << check_for_tab_characters(filename)
46
+ # error_messages << check_for_extra_spaces(filename)
47
+ # end
48
+ # end
49
+ # expect(error_messages.compact).to be_well_formed
50
+ # end
51
+ # end
@@ -0,0 +1,150 @@
1
+ $:.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'fileutils'
6
+ require 'timecop'
7
+ require 'pp'
8
+ require 'pry'
9
+
10
+ if RUBY_PLATFORM != "java"
11
+ if ENV['TRAVIS']
12
+ require 'coveralls'
13
+ Coveralls.wear!
14
+ elsif ENV['COVERAGE'] && RUBY_VERSION > "1.8"
15
+ require 'simplecov'
16
+ SimpleCov.start do
17
+ add_filter 'spec'
18
+ add_group 'Core', 'lib/mark_mapper'
19
+ add_group 'Rails', 'lib/rails'
20
+ add_group 'Extensions', 'lib/mark_mapper/extensions'
21
+ add_group 'Plugins', 'lib/mark_mapper/plugins'
22
+ add_group 'Associations', 'lib/mark_mapper/plugins/associations'
23
+ end
24
+ end
25
+ end
26
+
27
+ require 'marklogic'
28
+ require 'mark_mapper'
29
+
30
+ # These environment variables can be set if wanting to test against a database
31
+ # that is not on the local machine.
32
+ ENV["MARKMAPPER_SPEC_HOST"] ||= "localhost"
33
+ ENV["MARKMAPPER_SPEC_PORT"] ||= "8009"
34
+
35
+ ENV["MARKMAPPER_SPEC_APP_SERVICES_PORT"] ||= "8000"
36
+ ENV["MARKMAPPER_SPEC_ADMIN_PORT"] ||= "8001"
37
+ ENV["MARKMAPPER_SPEC_MANAGE_PORT"] ||= "8002"
38
+
39
+ ENV["MARKMAPPER_SPEC_USER"] ||= "admin"
40
+ ENV["MARKMAPPER_SPEC_PASSWORD"] ||= "admin"
41
+ ENV["MARKMAPPER_SKIP_APP_CREATION"] ||= "false"
42
+
43
+ # These are used when creating any connection in the test suite.
44
+ HOST = ENV["MARKMAPPER_SPEC_HOST"]
45
+ PORT = ENV["MARKMAPPER_SPEC_PORT"].to_i
46
+
47
+ APP_SERVICES_PORT = ENV["MARKMAPPER_SPEC_APP_SERVICES_PORT"]
48
+ MANAGE_PORT = ENV["MARKMAPPER_SPEC_MANAGE_PORT"]
49
+ ADMIN_PORT = ENV["MARKMAPPER_SPEC_ADMIN_PORT"]
50
+
51
+ USER = ENV["MARKMAPPER_SPEC_USER"]
52
+ PASSWORD = ENV["MARKMAPPER_SPEC_PASSWORD"]
53
+
54
+ ADMIN_USER = ENV["MARKMAPPER_SPEC_ADMIN_USER"]
55
+ ADMIN_PASSWORD = ENV["MARKMAPPER_SPEC_ADMIN_PASSWORD"]
56
+
57
+ MarkLogic::Connection.configure({
58
+ :host => HOST,
59
+ :manage_port => MANAGE_PORT,
60
+ :admin_port => ADMIN_PORT,
61
+ :app_services_port => APP_SERVICES_PORT,
62
+ :default_user => ADMIN_USER,
63
+ :default_password => ADMIN_PASSWORD
64
+ })
65
+
66
+ CONNECTION = MarkLogic::Connection.new(HOST, PORT)
67
+ MarkMapper.application = MarkLogic::Application.new("markmapper-application-test", connection: CONNECTION )
68
+ MarkMapper.application.stale?
69
+
70
+ MarkMapper.logger.level = Logger::DEBUG
71
+
72
+ def Doc(name='Class', &block)
73
+ klass = Class.new
74
+ klass.class_eval do
75
+ include MarkMapper::Document
76
+
77
+ if name
78
+ class_eval "def self.name; '#{name}' end"
79
+ class_eval "def self.to_s; '#{name}' end"
80
+ else
81
+ set_collection_name :test
82
+ end
83
+ end
84
+
85
+ klass.class_eval(&block) if block_given?
86
+ klass.collection.remove if klass.database.exists?
87
+ klass
88
+ end
89
+
90
+ def EDoc(name='Class', &block)
91
+ klass = Class.new do
92
+ include MarkMapper::EmbeddedDocument
93
+
94
+ if name
95
+ class_eval "def self.name; '#{name}' end"
96
+ class_eval "def self.to_s; '#{name}' end"
97
+ end
98
+ end
99
+
100
+ klass.class_eval(&block) if block_given?
101
+ klass
102
+ end
103
+
104
+ def drop_indexes(klass)
105
+ klass.collection.drop_indexes if klass.database.collection_names.include?(klass.collection.name)
106
+ end
107
+
108
+ log_dir = File.expand_path('../../log', __FILE__)
109
+ FileUtils.mkdir_p(log_dir) unless File.exist?(log_dir)
110
+ logger = Logger.new(log_dir + '/test.log')
111
+
112
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
113
+
114
+ RSpec.configure do |config|
115
+ # config.filter_run_excluding :skip => true
116
+ config.expect_with :rspec do |c|
117
+ c.syntax = [:should, :expect]
118
+ end
119
+
120
+ config.fail_fast = true
121
+
122
+ config.before(:all) do
123
+ @application = MarkMapper.application.tap do |app|
124
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:_id, :type => 'string'))
125
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:name, :type => 'string'))
126
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:body, :type => 'string'))
127
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:age, :type => 'int'))
128
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:first_name, :type => 'string'))
129
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:position, :type => 'int'))
130
+ app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:weight, :type => 'int'))
131
+ end
132
+ @application.sync
133
+ @database = @application.content_databases[0]
134
+ @database.clear
135
+ end
136
+
137
+ config.around(:each, :without_connection) do |example|
138
+ old, MarkMapper.connection = MarkMapper.connection, nil
139
+ example.run
140
+ MarkMapper.connection = old
141
+ end
142
+
143
+ config.after(:suite) do
144
+ puts "CLEANING UP AFTER ALL TESTS FINISHED"
145
+ MarkLogic::Application.new("markmapper-application-test", :port => PORT).drop
146
+ end
147
+ end
148
+
149
+ operators = %w{gt lt ge le ne eq asc desc}
150
+ SymbolOperators = operators
@@ -0,0 +1,15 @@
1
+ RSpec::Matchers.define :have_error_on do |*args|
2
+ match do |model|
3
+ field = args.dup.shift
4
+ error_messages = args
5
+
6
+ model.valid?
7
+ model.errors[field].any?
8
+ end
9
+ end
10
+
11
+ RSpec::Matchers.define :have_index do |index_name|
12
+ match do |model|
13
+ model.collection.index_information.detect { |index| index[0] == index_name }.present?
14
+ end
15
+ end
@@ -0,0 +1,256 @@
1
+ # custom type
2
+ class WindowSize
3
+ attr_reader :width, :height
4
+
5
+ def self.to_marklogic(value)
6
+ value.to_a
7
+ end
8
+
9
+ def self.from_marklogic(value)
10
+ value.is_a?(self) ? value : WindowSize.new(value)
11
+ end
12
+
13
+ def initialize(*args)
14
+ @width, @height = args.flatten
15
+ end
16
+
17
+ def to_a
18
+ [width, height]
19
+ end
20
+
21
+ def ==(other)
22
+ other.is_a?(self.class) && other.width == width && other.height == height
23
+ end
24
+ end
25
+
26
+ module AccountsExtensions
27
+ def inactive
28
+ all(:last_logged_in => nil)
29
+ end
30
+ end
31
+
32
+ class Post
33
+ include MarkMapper::Document
34
+
35
+ key :title, String
36
+ key :body, String
37
+
38
+ many :comments, :as => :commentable, :class_name => 'PostComment'
39
+
40
+ timestamps!
41
+ end
42
+
43
+ class PostComment
44
+ include MarkMapper::Document
45
+
46
+ key :username, String, :default => 'Anonymous'
47
+ key :body, String
48
+
49
+ key :commentable_id, ObjectId
50
+ key :commentable_type, String
51
+ belongs_to :commentable, :polymorphic => true
52
+
53
+ timestamps!
54
+ end
55
+
56
+ class Address
57
+ include MarkMapper::EmbeddedDocument
58
+
59
+ key :address, String
60
+ key :city, String
61
+ key :state, String
62
+ key :zip, Integer
63
+ end
64
+
65
+ class Message
66
+ include MarkMapper::Document
67
+
68
+ key :body, String
69
+ key :position, Integer
70
+ key :room_id, ObjectId
71
+
72
+ belongs_to :room
73
+ end
74
+
75
+ class Enter < Message; end
76
+ class Exit < Message; end
77
+ class Chat < Message; end
78
+
79
+ class Room
80
+ include MarkMapper::Document
81
+
82
+ key :name, String
83
+ many :messages, :polymorphic => true, :order => 'position' do
84
+ def older
85
+ all(:position => {'$gt' => 5})
86
+ end
87
+ end
88
+ many :latest_messages, :class_name => 'Message', :order => 'position desc', :limit => 2
89
+
90
+ many :accounts, :polymorphic => true, :extend => AccountsExtensions
91
+ end
92
+
93
+ class Account
94
+ include MarkMapper::Document
95
+
96
+ key :room_id, ObjectId
97
+ key :last_logged_in, Time
98
+
99
+ belongs_to :room
100
+ end
101
+ class AccountUser < Account; end
102
+ class Bot < Account; end
103
+
104
+ class Answer
105
+ include MarkMapper::Document
106
+
107
+ key :body, String
108
+ end
109
+
110
+ module CollaboratorsExtensions
111
+ def top
112
+ first
113
+ end
114
+ end
115
+
116
+ class Project
117
+ include MarkMapper::Document
118
+
119
+ key :name, String
120
+
121
+ many :collaborators, :extend => CollaboratorsExtensions
122
+ many :statuses, :order => 'position' do
123
+ def open
124
+ all(:name => %w(New Assigned))
125
+ end
126
+ end
127
+
128
+ many :addresses
129
+ end
130
+
131
+ class Collaborator
132
+ include MarkMapper::Document
133
+ key :project_id, ObjectId
134
+ key :name, String
135
+ belongs_to :project
136
+ end
137
+
138
+ class Status
139
+ include MarkMapper::Document
140
+
141
+ scope :complete, where(:name => 'Complete')
142
+
143
+ def self.by_position(position)
144
+ where(:position => position)
145
+ end
146
+
147
+ key :project_id, ObjectId
148
+ key :target_id, ObjectId
149
+ key :target_type, String
150
+ key :name, String, :required => true
151
+ key :position, Integer
152
+
153
+ belongs_to :project
154
+ belongs_to :target, :polymorphic => true
155
+ end
156
+
157
+ class Media
158
+ include MarkMapper::EmbeddedDocument
159
+
160
+ key :file, String
161
+ key :visible, Boolean
162
+ end
163
+
164
+ class Video < Media
165
+ key :length, Integer
166
+ end
167
+
168
+ class Image < Media
169
+ key :width, Integer
170
+ key :height, Integer
171
+ end
172
+
173
+ class Music < Media
174
+ key :bitrate, String
175
+ end
176
+
177
+ class Catalog
178
+ include MarkMapper::Document
179
+
180
+ many :medias, :polymorphic => true do
181
+ def visible
182
+ # for some reason we can't use select here
183
+ find_all { |m| m.visible? }
184
+ end
185
+ end
186
+ end
187
+
188
+ module TrModels
189
+ class Transport
190
+ include MarkMapper::EmbeddedDocument
191
+
192
+ key :license_plate, String
193
+ key :purchased_on, Date
194
+ end
195
+
196
+ class Car < TrModels::Transport
197
+ include MarkMapper::EmbeddedDocument
198
+
199
+ key :model, String
200
+ key :year, Integer
201
+ end
202
+
203
+ class Bus < TrModels::Transport
204
+ include MarkMapper::EmbeddedDocument
205
+
206
+ key :max_passengers, Integer
207
+ end
208
+
209
+ class Ambulance < TrModels::Transport
210
+ include MarkMapper::EmbeddedDocument
211
+
212
+ key :icu, Boolean
213
+ end
214
+
215
+ class Fleet
216
+ include MarkMapper::Document
217
+
218
+ module TransportsExtension
219
+ def to_be_replaced
220
+ # for some reason we can't use select
221
+ find_all { |t| t.purchased_on < 2.years.ago.to_date }
222
+ end
223
+ end
224
+
225
+ many :transports, :polymorphic => true, :class_name => "TrModels::Transport", :extend => TransportsExtension
226
+ key :name, String
227
+ end
228
+ end
229
+
230
+ module News
231
+ class Paper
232
+ include MarkMapper::Document
233
+ end
234
+
235
+ class Article
236
+ include MarkMapper::Document
237
+ end
238
+ end
239
+
240
+ class AltUser
241
+ include MarkMapper::Document
242
+ end
243
+
244
+ class Human
245
+ include MarkMapper::EmbeddedDocument
246
+
247
+ key :name, String
248
+ embedded_in :post
249
+ end
250
+
251
+ class Robot
252
+ include MarkMapper::EmbeddedDocument
253
+
254
+ key :serial_number, String
255
+ embedded_in :post
256
+ end