mongoid_spacial 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +28 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +126 -0
  6. data/Rakefile +42 -0
  7. data/VERSION +1 -0
  8. data/lib/mongoid_spacial.rb +11 -0
  9. data/lib/mongoid_spacial/contexts/mongo.rb +126 -0
  10. data/lib/mongoid_spacial/criteria.rb +5 -0
  11. data/lib/mongoid_spacial/criterion.rb +8 -0
  12. data/lib/mongoid_spacial/criterion/complex.rb +19 -0
  13. data/lib/mongoid_spacial/criterion/inclusion.rb +14 -0
  14. data/lib/mongoid_spacial/criterion/near_spacial.rb +43 -0
  15. data/lib/mongoid_spacial/criterion/within_spacial.rb +56 -0
  16. data/lib/mongoid_spacial/extentions/hash/criteria_helpers.rb +22 -0
  17. data/lib/mongoid_spacial/extentions/symbol/inflections.rb +46 -0
  18. data/lib/mongoid_spacial/field_option.rb +36 -0
  19. data/lib/mongoid_spacial/finders.rb +5 -0
  20. data/lib/mongoid_spacial/spacial.rb +37 -0
  21. data/lib/mongoid_spacial/spacial/core_ext.rb +27 -0
  22. data/lib/mongoid_spacial/spacial/document.rb +31 -0
  23. data/lib/mongoid_spacial/spacial/formulas.rb +47 -0
  24. data/mongoid_spacial.gemspec +172 -0
  25. data/spec/config/mongod.conf +3 -0
  26. data/spec/config/mongoid.yml +18 -0
  27. data/spec/functional/mongoid/contexts/mongo_spec.rb +101 -0
  28. data/spec/functional/mongoid/criterion/inclusion_spec.rb +356 -0
  29. data/spec/models/account.rb +19 -0
  30. data/spec/models/acolyte.rb +9 -0
  31. data/spec/models/address.rb +62 -0
  32. data/spec/models/address_component.rb +5 -0
  33. data/spec/models/agent.rb +10 -0
  34. data/spec/models/alert.rb +5 -0
  35. data/spec/models/animal.rb +21 -0
  36. data/spec/models/answer.rb +4 -0
  37. data/spec/models/bar.rb +9 -0
  38. data/spec/models/birthday.rb +13 -0
  39. data/spec/models/book.rb +5 -0
  40. data/spec/models/business.rb +7 -0
  41. data/spec/models/callbacks.rb +57 -0
  42. data/spec/models/category.rb +13 -0
  43. data/spec/models/circus.rb +7 -0
  44. data/spec/models/comment.rb +13 -0
  45. data/spec/models/country_code.rb +6 -0
  46. data/spec/models/description.rb +11 -0
  47. data/spec/models/division.rb +5 -0
  48. data/spec/models/drug.rb +5 -0
  49. data/spec/models/employer.rb +5 -0
  50. data/spec/models/entry.rb +6 -0
  51. data/spec/models/event.rb +20 -0
  52. data/spec/models/favorite.rb +6 -0
  53. data/spec/models/fruits.rb +11 -0
  54. data/spec/models/game.rb +18 -0
  55. data/spec/models/ghost.rb +7 -0
  56. data/spec/models/house.rb +4 -0
  57. data/spec/models/inheritance.rb +90 -0
  58. data/spec/models/league.rb +5 -0
  59. data/spec/models/location.rb +5 -0
  60. data/spec/models/login.rb +6 -0
  61. data/spec/models/membership.rb +4 -0
  62. data/spec/models/mixed_drink.rb +4 -0
  63. data/spec/models/name.rb +13 -0
  64. data/spec/models/namespacing.rb +11 -0
  65. data/spec/models/observed.rb +41 -0
  66. data/spec/models/override.rb +16 -0
  67. data/spec/models/owner.rb +6 -0
  68. data/spec/models/page.rb +5 -0
  69. data/spec/models/page_question.rb +4 -0
  70. data/spec/models/paranoid_post.rb +18 -0
  71. data/spec/models/parents.rb +32 -0
  72. data/spec/models/patient.rb +15 -0
  73. data/spec/models/person.rb +146 -0
  74. data/spec/models/pet.rb +7 -0
  75. data/spec/models/pet_owner.rb +6 -0
  76. data/spec/models/phone.rb +7 -0
  77. data/spec/models/player.rb +23 -0
  78. data/spec/models/post.rb +26 -0
  79. data/spec/models/preference.rb +9 -0
  80. data/spec/models/question.rb +8 -0
  81. data/spec/models/quiz.rb +6 -0
  82. data/spec/models/rating.rb +8 -0
  83. data/spec/models/river.rb +20 -0
  84. data/spec/models/role.rb +5 -0
  85. data/spec/models/service.rb +6 -0
  86. data/spec/models/shelf.rb +5 -0
  87. data/spec/models/slave_address_numbers.rb +14 -0
  88. data/spec/models/survey.rb +5 -0
  89. data/spec/models/tag.rb +6 -0
  90. data/spec/models/tracking_id_validation_history.rb +25 -0
  91. data/spec/models/translation.rb +5 -0
  92. data/spec/models/tree.rb +9 -0
  93. data/spec/models/user.rb +9 -0
  94. data/spec/models/user_account.rb +10 -0
  95. data/spec/models/vet_visit.rb +5 -0
  96. data/spec/models/video.rb +9 -0
  97. data/spec/models/wiki_page.rb +6 -0
  98. data/spec/spec_helper.rb +41 -0
  99. data/spec/support/authentication.rb +29 -0
  100. data/spec/unit/mongoid_spacial/criterion/complex_spec.rb +15 -0
  101. data/spec/unit/mongoid_spacial/criterion/inclusion_spec.rb +0 -0
  102. data/spec/unit/mongoid_spacial/criterion/near_spacial_spec.rb +39 -0
  103. data/spec/unit/mongoid_spacial/criterion/within_spacial_spec.rb +52 -0
  104. metadata +280 -0
@@ -0,0 +1,19 @@
1
+ class Account
2
+ include Mongoid::Document
3
+ field :number, :type => String
4
+ field :balance, :type => String
5
+ field :nickname, :type => String
6
+ field :name, :type => String
7
+ key :name
8
+
9
+ embeds_many :memberships
10
+ referenced_in :creator, :class_name => "User", :foreign_key => :creator_id
11
+ referenced_in :person
12
+ references_many :alerts
13
+ references_and_referenced_in_many :agents
14
+
15
+ attr_accessible :nickname, :name
16
+
17
+ validates_presence_of :name
18
+ validates_length_of :name, :maximum => 10, :on => :create
19
+ end
@@ -0,0 +1,9 @@
1
+ class Acolyte
2
+ include Mongoid::Document
3
+ field :status
4
+ field :name
5
+
6
+ scope :active, where(:status => "active")
7
+
8
+ default_scope asc(:name)
9
+ end
@@ -0,0 +1,62 @@
1
+ class Address
2
+ include Mongoid::Document
3
+
4
+ attr_accessor :mode
5
+
6
+ field :address_type
7
+ field :number, :type => Integer
8
+ field :street
9
+ field :city
10
+ field :state
11
+ field :post_code
12
+ field :parent_title
13
+ field :services, :type => Array
14
+ field :latlng, :type => Array
15
+ key :street
16
+ embeds_many :locations
17
+
18
+ embedded_in :addressable, :polymorphic => true do
19
+ def extension
20
+ "Testing"
21
+ end
22
+ def doctor?
23
+ title == "Dr"
24
+ end
25
+ end
26
+
27
+ accepts_nested_attributes_for :locations
28
+
29
+ referenced_in :account
30
+
31
+ scope :without_postcode, where(:postcode => nil)
32
+ named_scope :rodeo, where(:street => "Rodeo Dr") do
33
+ def mansion?
34
+ all? { |address| address.street == "Rodeo Dr" }
35
+ end
36
+ end
37
+
38
+ validates_presence_of :street, :on => :update
39
+ validates_format_of :street, :with => /\D/, :allow_nil => true
40
+
41
+ def set_parent=(set = false)
42
+ self.parent_title = addressable.title if set
43
+ end
44
+
45
+ def <=>(other)
46
+ street <=> other.street
47
+ end
48
+
49
+ class << self
50
+ def california
51
+ where(:state => "CA")
52
+ end
53
+
54
+ def homes
55
+ where(:address_type => "Home")
56
+ end
57
+
58
+ def streets
59
+ all.map(&:street)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ class AddressComponent
2
+ include Mongoid::Document
3
+ field :street, :type => String
4
+ embedded_in :person
5
+ end
@@ -0,0 +1,10 @@
1
+ class Agent
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps::Updated
4
+ field :title
5
+ field :number
6
+ embeds_many :names, :as => :namable
7
+ referenced_in :game
8
+
9
+ references_and_referenced_in_many :accounts
10
+ end
@@ -0,0 +1,5 @@
1
+ class Alert
2
+ include Mongoid::Document
3
+ field :message, :type => String
4
+ referenced_in :account
5
+ end
@@ -0,0 +1,21 @@
1
+ class Animal
2
+ include Mongoid::Document
3
+ field :name
4
+ field :tags, :type => Array
5
+ key :name
6
+
7
+ embedded_in :person
8
+ embedded_in :circus
9
+
10
+ validates_format_of :name, :without => /\$\$\$/
11
+
12
+ accepts_nested_attributes_for :person
13
+
14
+ def tag_list
15
+ tags.join(", ")
16
+ end
17
+
18
+ def tag_list=(_tag_list)
19
+ self.tags = _tag_list.split(",").map(&:strip)
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ class Answer
2
+ include Mongoid::Document
3
+ embedded_in :question
4
+ end
@@ -0,0 +1,9 @@
1
+ class Bar
2
+ include Mongoid::Document
3
+ include Mongoid::Spacial::Document
4
+
5
+ field :name, :type => String
6
+ field :location, :type => Array, :spacial => true
7
+ references_one :rating, :as => :ratable
8
+ spacial_index :location
9
+ end
@@ -0,0 +1,13 @@
1
+ class Birthday
2
+ include Mongoid::Document
3
+ field :title
4
+ field :date, :type => Date
5
+ embedded_in :owner, :inverse_of => :birthdays
6
+
7
+ def self.each_day(start_date, end_date)
8
+ groups = only(:date).asc(:date).where(:date.gte => start_date, :date.lte => end_date).group
9
+ groups.each do |date, group|
10
+ yield(date, group)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class Book
2
+ include Mongoid::Document
3
+ field :title, :type => String
4
+ references_one :rating, :as => :ratable, :dependent => :nullify
5
+ end
@@ -0,0 +1,7 @@
1
+ class Business
2
+ include Mongoid::Document
3
+
4
+ set_database :secondary
5
+
6
+ field :name
7
+ end
@@ -0,0 +1,57 @@
1
+ class Artist
2
+ include Mongoid::Document
3
+ field :name
4
+ embeds_many :songs
5
+ embeds_many :labels
6
+
7
+ before_create :before_create_stub
8
+ after_create :create_songs
9
+ before_save :before_save_stub
10
+ before_destroy :before_destroy_stub
11
+
12
+ protected
13
+ def before_create_stub
14
+ true
15
+ end
16
+
17
+ def before_save_stub
18
+ true
19
+ end
20
+
21
+ def before_destroy_stub
22
+ true
23
+ end
24
+
25
+ def create_songs
26
+ 2.times { |n| songs.create!(:title => "#{n}") }
27
+ end
28
+ end
29
+
30
+ class Song
31
+ include Mongoid::Document
32
+ field :title
33
+ embedded_in :artist
34
+ end
35
+
36
+ class Label
37
+ include Mongoid::Document
38
+ field :name
39
+ embedded_in :artist
40
+ before_validation :cleanup
41
+
42
+ private
43
+ def cleanup
44
+ self.name = self.name.downcase.capitalize
45
+ end
46
+ end
47
+
48
+ class ValidationCallback
49
+ include Mongoid::Document
50
+ field :history, :type => Array, :default => []
51
+ validate do
52
+ self.history << :validate
53
+ end
54
+
55
+ before_validation { self.history << :before_validation }
56
+ after_validation { self.history << :after_validation }
57
+ end
@@ -0,0 +1,13 @@
1
+ class RootCategory
2
+ include Mongoid::Document
3
+ embeds_many :categories
4
+ end
5
+
6
+ class Category
7
+ include Mongoid::Document
8
+ embedded_in :root_category
9
+ embedded_in :category
10
+ embeds_many :categories
11
+
12
+ field :name
13
+ end
@@ -0,0 +1,7 @@
1
+ class Circus
2
+ include Mongoid::Document
3
+
4
+ field :name
5
+
6
+ embeds_many :animals
7
+ end
@@ -0,0 +1,13 @@
1
+ class Comment
2
+ include Mongoid::Document
3
+ include Mongoid::Versioning
4
+ include Mongoid::Timestamps
5
+ field :title, :type => String
6
+ field :text, :type => String
7
+ key :text, :type => String
8
+
9
+ referenced_in :movie
10
+ referenced_in :rating
11
+ validates :title, :presence => true
12
+ validates :movie, :rating, :associated => true
13
+ end
@@ -0,0 +1,6 @@
1
+ class CountryCode
2
+ include Mongoid::Document
3
+ field :code, :type => Integer
4
+ key :code
5
+ embedded_in :phone_number, :class_name => "Phone"
6
+ end
@@ -0,0 +1,11 @@
1
+ class Description
2
+ include Mongoid::Document
3
+
4
+ field :details
5
+
6
+ referenced_in :user
7
+ referenced_in :updater, :class_name => 'User'
8
+
9
+ validates :user, :associated => true
10
+ validates :details, :presence => true
11
+ end
@@ -0,0 +1,5 @@
1
+ class Division
2
+ include Mongoid::Document
3
+ field :name, :type => String
4
+ embedded_in :league
5
+ end
@@ -0,0 +1,5 @@
1
+ class Drug
2
+ include Mongoid::Document
3
+ field :name, :type => String
4
+ referenced_in :person
5
+ end
@@ -0,0 +1,5 @@
1
+ class Employer
2
+ def id
3
+ "1"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class Entry
2
+ include Mongoid::Document
3
+ field :title, :type => String
4
+ field :body, :type => String
5
+ recursively_embeds_many
6
+ end
@@ -0,0 +1,20 @@
1
+ class Event
2
+ include Mongoid::Document
3
+
4
+ field :title
5
+ field :date, :type => Date
6
+ references_and_referenced_in_many \
7
+ :administrators,
8
+ :class_name => 'Person',
9
+ :inverse_of => :administrated_events,
10
+ :dependent => :nullify
11
+ referenced_in :owner
12
+
13
+ def self.each_day(start_date, end_date)
14
+ groups = only(:date).asc(:date).where(:date.gte => start_date, :date.lte => end_date).group
15
+ groups.each do |hash|
16
+ yield(hash["date"], hash["group"])
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,6 @@
1
+ class Favorite
2
+ include Mongoid::Document
3
+ field :title
4
+ validates_uniqueness_of :title, :case_sensitive => false
5
+ embedded_in :perp, :inverse_of => :favorites
6
+ end
@@ -0,0 +1,11 @@
1
+ module Fruits
2
+ class Apple
3
+ include Mongoid::Document
4
+ references_many :bananas, :class_name => "Fruits::Banana"
5
+ end
6
+
7
+ class Banana
8
+ include Mongoid::Document
9
+ referenced_in :apple, :class_name => "Fruits::Apple"
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ class Game
2
+ include Mongoid::Document
3
+ field :high_score, :type => Integer, :default => 500
4
+ field :score, :type => Integer, :default => 0
5
+ field :name
6
+ referenced_in :person, :index => true
7
+ references_one :video, :validate => false
8
+ accepts_nested_attributes_for :person
9
+ cache
10
+
11
+ validates_format_of :name, :without => /\$\$\$/
12
+
13
+ attr_protected :_id
14
+
15
+ set_callback(:initialize, :after) do |document|
16
+ write_attribute("name", "Testing") unless name
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ class Ghost
2
+ include Mongoid::Document
3
+
4
+ field :name, :type => String
5
+
6
+ referenced_in :movie, :autosave => true
7
+ end
@@ -0,0 +1,4 @@
1
+ class House
2
+ include Mongoid::Document
3
+ field :name, :type => String
4
+ end
@@ -0,0 +1,90 @@
1
+ class Canvas
2
+ include Mongoid::Document
3
+ field :name
4
+ embeds_many :shapes
5
+ embeds_one :writer
6
+ embeds_one :palette
7
+
8
+ def render
9
+ shapes.each { |shape| render }
10
+ end
11
+ end
12
+
13
+ class Browser < Canvas
14
+ field :version, :type => Integer
15
+ def render; end
16
+ end
17
+
18
+ class Firefox < Browser
19
+ field :user_agent
20
+ def render; end
21
+ end
22
+
23
+ class Shape
24
+ include Mongoid::Document
25
+ field :x, :type => Integer, :default => 0
26
+ field :y, :type => Integer, :default => 0
27
+
28
+ embedded_in :canvas
29
+
30
+ def render; end
31
+ end
32
+
33
+ class Square < Shape
34
+ field :width, :type => Integer, :default => 0
35
+ field :height, :type => Integer, :default => 0
36
+ end
37
+
38
+ class Circle < Shape
39
+ field :radius, :type => Integer, :default => 0
40
+ end
41
+
42
+ class Writer
43
+ include Mongoid::Document
44
+ field :speed, :type => Integer, :default => 0
45
+
46
+ embedded_in :canvas
47
+
48
+ def write; end
49
+ end
50
+
51
+ class HtmlWriter < Writer
52
+ def write; end
53
+ end
54
+
55
+ class PdfWriter < Writer
56
+ def write; end
57
+ end
58
+
59
+ class Palette
60
+ include Mongoid::Document
61
+ embedded_in :canvas
62
+ embeds_many :tools
63
+ end
64
+
65
+ class Tool
66
+ include Mongoid::Document
67
+ embedded_in :palette
68
+ end
69
+
70
+ class Pencil < Tool; end
71
+
72
+ class Eraser < Tool; end
73
+
74
+ ########################################
75
+ # These are for references relationships
76
+ ########################################
77
+ class ShippingContainer
78
+ include Mongoid::Document
79
+ references_many :vehicles
80
+ end
81
+ class Vehicle
82
+ include Mongoid::Document
83
+ referenced_in :shipping_container
84
+ end
85
+ class Bed; end
86
+ class Car < Vehicle; end
87
+ class Truck < Vehicle
88
+ embeds_one :bed
89
+ end
90
+