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,5 @@
1
+ class League
2
+ include Mongoid::Document
3
+ embeds_many :divisions
4
+ accepts_nested_attributes_for :divisions, :allow_destroy => true
5
+ end
@@ -0,0 +1,5 @@
1
+ class Location
2
+ include Mongoid::Document
3
+ field :name
4
+ embedded_in :address
5
+ end
@@ -0,0 +1,6 @@
1
+ class Login
2
+ include Mongoid::Document
3
+ field :username
4
+ key :username
5
+ validates_uniqueness_of :username
6
+ end
@@ -0,0 +1,4 @@
1
+ class Membership
2
+ include Mongoid::Document
3
+ embedded_in :account
4
+ end
@@ -0,0 +1,4 @@
1
+ class MixedDrink
2
+ include Mongoid::Document
3
+ field :name
4
+ end
@@ -0,0 +1,13 @@
1
+ class Name
2
+ include Mongoid::Document
3
+ field :first_name
4
+ field :last_name
5
+ field :parent_title
6
+ key :first_name, :last_name
7
+ embeds_many :translations
8
+ embedded_in :namable, :polymorphic => true
9
+
10
+ def set_parent=(set = false)
11
+ self.parent_title = namable.title if set
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Medical
2
+ class Patient
3
+ include Mongoid::Document
4
+ field :name
5
+ embeds_many :prescriptions, :class_name => "Medical::Prescription"
6
+ end
7
+ class Prescription
8
+ include Mongoid::Document
9
+ field :name
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ class Actor
2
+ include Mongoid::Document
3
+ field :name
4
+ end
5
+
6
+ class Actress < Actor
7
+ end
8
+
9
+ class ActorObserver < Mongoid::Observer
10
+ attr_reader :last_after_create_record
11
+
12
+ def after_create(record)
13
+ @last_after_create_record = record
14
+ end
15
+ end
16
+
17
+ class CallbackRecorder < Mongoid::Observer
18
+ observe :actor
19
+
20
+ attr_reader :last_callback, :call_count, :last_record
21
+
22
+ def initialize
23
+ reset
24
+ super
25
+ end
26
+
27
+ def reset
28
+ @last_callback = nil
29
+ @call_count = Hash.new(0)
30
+ @last_record = {}
31
+ end
32
+
33
+ Mongoid::Callbacks::CALLBACKS.each do |callback|
34
+ define_method(callback) do |record, &block|
35
+ @last_callback = callback
36
+ @call_count[callback] += 1
37
+ @last_record[callback] = record
38
+ block ? block.call : true
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ class Override
2
+ include Mongoid::Document
3
+
4
+ def self.public_method
5
+ end
6
+
7
+ protected
8
+
9
+ def self.protected_method
10
+ end
11
+
12
+ private
13
+
14
+ def self.private_method
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ class Owner
2
+ include Mongoid::Document
3
+ field :name
4
+ references_many :events
5
+ embeds_many :birthdays
6
+ end
@@ -0,0 +1,5 @@
1
+ class Page
2
+ include Mongoid::Document
3
+ embedded_in :quiz
4
+ embeds_many :page_questions
5
+ end
@@ -0,0 +1,4 @@
1
+ class PageQuestion
2
+ include Mongoid::Document
3
+ embedded_in :page
4
+ end
@@ -0,0 +1,18 @@
1
+ class ParanoidPost
2
+ include Mongoid::Document
3
+ include Mongoid::Versioning
4
+ include Mongoid::Timestamps
5
+ include Mongoid::Paranoia
6
+ field :title
7
+ referenced_in :person
8
+
9
+ references_and_referenced_in_many :tags
10
+
11
+ named_scope :recent, where(:created_at => { "$lt" => Time.now, "$gt" => 30.days.ago })
12
+
13
+ class << self
14
+ def old
15
+ where(:created_at => { "$lt" => 30.days.ago })
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ class ParentDoc
2
+ include Mongoid::Document
3
+
4
+ embeds_many :child_docs
5
+
6
+ field :statistic
7
+ field :children_order, :type => Array, :default => [] # hold all the children's id
8
+ end
9
+
10
+
11
+ class ChildDoc
12
+ include Mongoid::Document
13
+
14
+ embedded_in :parent_doc
15
+
16
+ attr_writer :position
17
+
18
+ after_save :update_position
19
+
20
+ def position
21
+ exsited_position = parent_doc.children_order.index(id)
22
+ exsited_position ? exsited_position + 1 : parent_doc.aspects.size
23
+ end
24
+
25
+ def update_position
26
+ if @position && (@position.to_i > 0)
27
+ parent_doc.children_order.delete(id)
28
+ parent_doc.children_order.insert(@position.to_i - 1, id)
29
+ parent_doc.save
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ class Email
2
+ include Mongoid::Document
3
+ field :address
4
+ validates_uniqueness_of :address
5
+ embedded_in :patient
6
+ end
7
+
8
+ class Patient
9
+ include Mongoid::Document
10
+ field :title
11
+ store_in :inpatient
12
+ embeds_many :addresses, :as => :addressable
13
+ embeds_one :email
14
+ validates_presence_of :title, :on => :create
15
+ end
@@ -0,0 +1,146 @@
1
+ class Person
2
+ include Mongoid::Document
3
+ include Mongoid::MultiParameterAttributes
4
+ include Mongoid::Timestamps
5
+ include Mongoid::Versioning
6
+
7
+ attr_accessor :mode
8
+
9
+ class_attribute :somebody_elses_important_class_options
10
+ self.somebody_elses_important_class_options = { :keep_me_around => true }
11
+
12
+ field :title
13
+ field :terms, :type => Boolean
14
+ field :pets, :type => Boolean, :default => false
15
+ field :age, :type => Integer, :default => 100
16
+ field :dob, :type => Date
17
+ field :employer_id
18
+ field :lunch_time, :type => Time
19
+ field :aliases, :type => Array
20
+ field :map, :type => Hash
21
+ field :score, :type => Integer
22
+ field :blood_alcohol_content, :type => Float, :default => lambda{ 0.0 }
23
+ field :last_drink_taken_at, :type => Date, :default => lambda { 1.day.ago.in_time_zone("Alaska") }
24
+ field :ssn
25
+ field :owner_id, :type => Integer
26
+ field :security_code
27
+ field :reading, :type => Object
28
+ field :bson_id, :type => BSON::ObjectId
29
+
30
+ index :age
31
+ index :addresses
32
+ index :dob
33
+ index :name
34
+ index :title
35
+ index :ssn, :unique => true
36
+
37
+ validates_format_of :ssn, :without => /\$\$\$/
38
+
39
+ attr_reader :rescored
40
+
41
+ attr_protected :security_code, :owner_id
42
+
43
+ embeds_many :favorites, :order => :title.desc, :inverse_of => :perp
44
+ embeds_many :videos, :order => [[ :title, :asc ]]
45
+ embeds_many :phone_numbers, :class_name => "Phone"
46
+ embeds_many :addresses, :as => :addressable do
47
+ def extension
48
+ "Testing"
49
+ end
50
+ def find_by_street(street)
51
+ @target.select { |doc| doc.street == street }
52
+ end
53
+ end
54
+ embeds_many :address_components
55
+ embeds_many :services
56
+
57
+ embeds_one :pet, :class_name => "Animal"
58
+ embeds_one :name, :as => :namable do
59
+ def extension
60
+ "Testing"
61
+ end
62
+ def dawkins?
63
+ first_name == "Richard" && last_name == "Dawkins"
64
+ end
65
+ end
66
+ embeds_one :quiz
67
+
68
+ accepts_nested_attributes_for :addresses
69
+ accepts_nested_attributes_for :name, :update_only => true
70
+ accepts_nested_attributes_for :pet, :allow_destroy => true
71
+ accepts_nested_attributes_for :game, :allow_destroy => true
72
+ accepts_nested_attributes_for :favorites, :allow_destroy => true, :limit => 5
73
+ accepts_nested_attributes_for :posts
74
+ accepts_nested_attributes_for :preferences
75
+ accepts_nested_attributes_for :quiz
76
+
77
+ references_one :game, :dependent => :destroy do
78
+ def extension
79
+ "Testing"
80
+ end
81
+ end
82
+
83
+ references_many \
84
+ :posts,
85
+ :dependent => :delete,
86
+ :order => :rating.desc do
87
+ def extension
88
+ "Testing"
89
+ end
90
+ end
91
+ references_many :paranoid_posts
92
+ references_and_referenced_in_many \
93
+ :preferences,
94
+ :index => true,
95
+ :dependent => :nullify,
96
+ :autosave => true,
97
+ :order => :value.desc
98
+ references_and_referenced_in_many :user_accounts
99
+ references_and_referenced_in_many :houses
100
+
101
+ references_many :drugs, :autosave => true
102
+ references_one :account, :autosave => true
103
+
104
+ references_and_referenced_in_many \
105
+ :administrated_events,
106
+ :class_name => 'Event',
107
+ :inverse_of => :administrators,
108
+ :dependent => :nullify
109
+
110
+ scope :minor, where(:age.lt => 18)
111
+ scope :without_ssn, without(:ssn)
112
+
113
+ def score_with_rescoring=(score)
114
+ @rescored = score.to_i + 20
115
+ self.score_without_rescoring = score
116
+ end
117
+
118
+ alias_method_chain :score=, :rescoring
119
+
120
+ def update_addresses
121
+ addresses.each do |address|
122
+ address.street = "Updated Address"
123
+ end
124
+ end
125
+
126
+ def employer=(emp)
127
+ self.employer_id = emp.id
128
+ end
129
+
130
+ class << self
131
+ def accepted
132
+ criteria.where(:terms => true)
133
+ end
134
+ def knight
135
+ criteria.where(:title => "Sir")
136
+ end
137
+ def old
138
+ criteria.where(:age => { "$gt" => 50 })
139
+ end
140
+ end
141
+
142
+ end
143
+
144
+ class Doctor < Person
145
+ field :specialty
146
+ end
@@ -0,0 +1,7 @@
1
+ class Pet
2
+ include Mongoid::Document
3
+ field :name
4
+ field :weight, :type => Float, :default => 0.0
5
+ embeds_many :vet_visits
6
+ embedded_in :pet_owner
7
+ end
@@ -0,0 +1,6 @@
1
+ class PetOwner
2
+ include Mongoid::Document
3
+ field :title
4
+ embeds_one :pet
5
+ embeds_one :address, :as => :addressable
6
+ end
@@ -0,0 +1,7 @@
1
+ class Phone
2
+ include Mongoid::Document
3
+ field :number
4
+ key :number
5
+ embeds_one :country_code
6
+ embedded_in :person
7
+ end
@@ -0,0 +1,23 @@
1
+ class Player
2
+ include Mongoid::Document
3
+ field :active, :type => Boolean
4
+ field :frags, :type => Integer
5
+ field :deaths, :type => Integer
6
+ field :status
7
+
8
+ named_scope :active, criteria.where(:active => true) do
9
+ def extension
10
+ "extension"
11
+ end
12
+ end
13
+ named_scope :inactive, :where => { :active => false }
14
+ named_scope :frags_over, lambda { |count| { :where => { :frags.gt => count } } }
15
+ named_scope :deaths_under, lambda { |count| criteria.where(:deaths.lt => count) }
16
+ scope :deaths_over, lambda { |count| criteria.where(:deaths.gt => count) }
17
+
18
+ class << self
19
+ def alive
20
+ criteria.where(:status => "Alive")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ class Post
2
+ include Mongoid::Document
3
+ include Mongoid::MultiParameterAttributes
4
+ include Mongoid::Versioning
5
+ include Mongoid::Timestamps
6
+
7
+ field :title, :type => String
8
+ field :content, :type => String
9
+ field :rating, :type => Integer
10
+
11
+ belongs_to :person
12
+ belongs_to :author, :foreign_key => :author_id, :class_name => "User"
13
+ has_and_belongs_to_many :tags
14
+ has_many :videos, :validate => false
15
+
16
+ scope :recent, where(:created_at => { "$lt" => Time.now, "$gt" => 30.days.ago })
17
+ scope :posting, where(:content.in => [ "Posting" ])
18
+
19
+ validates_format_of :title, :without => /\$\$\$/
20
+
21
+ class << self
22
+ def old
23
+ where(:created_at => { "$lt" => 30.days.ago })
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ class Preference
2
+ include Mongoid::Document
3
+ field :name, :type => String
4
+ field :value, :type => String
5
+ field :ranking, :type => Integer
6
+ has_and_belongs_to_many :people
7
+ validates_length_of :name, :minimum => 2, :allow_nil => true
8
+ scope :posting, where(:value.in => [ "Posting" ])
9
+ end