Sha256: 8950777ad18731fdc3ccbca38a6b3644ced493ffd08f12edb188a74d11d29e82

Contents?: true

Size: 1.42 KB

Versions: 53

Compression:

Stored size: 1.42 KB

Contents

class Auth::Work::Schedule

	include Mongoid::Document

	field :start_time, type: Time
	field :end_time, type: Time
	field :location_id, type: String
	field :for_object_id, type: String
	field :for_object_class, type: String
	field :can_do_cycles, type: Array, default: []

	def create_prev_not_exists
		created_document = Auth::Work::Schedule.
			where({
				"$and" => [
					{
						"location_id" => self.location_id
					},
					{
						"for_object_id" => self.for_object_id
					},
					{
						"for_object_class" => self.for_object_class
					},
					{
						"$or" => [
							{
								## the end time is within this start - end time
								"end_time" => {
									"$lte" => self.end_time,
									"$gte" => self.start_time
								}
								
							},
							{
								## the start time is within this start - end time.
								"start_time" => {
									"$gte" => self.start_time,
									"$lte" => self.end_time
								}
									
							},
							{
								## the start time is less than or equal to this start time, and the end time is greater than or equal to this end time.(envelope)
								"$and" => [
									"start_time" => {
										"$lte" => self.start_time
									},
									"end_time" => {
										"$gte" => self.end_time
									}
								]
							}
						]
					}
				]
			}).
			find_one_and_update(
				{
					"$setOnInsert" => self.attributes
				},
				{
					:upsert => true,
					:new => true
				}
			)
		
	end

end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
wordjelly-auth-1.6.0 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.9 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.8 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.7 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.6 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.5 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.4 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.3 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.2 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.1 app/models/auth/work/schedule.rb
wordjelly-auth-1.5.0 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.9 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.8 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.7 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.6 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.5 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.4 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.3 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.2 app/models/auth/work/schedule.rb
wordjelly-auth-1.4.0 app/models/auth/work/schedule.rb