mongoid_recurring 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7a8d2508fb0cd720a37d1a45bd165191f2e9b4f
4
+ data.tar.gz: 346dec8d6a1af3e1501b04f751b269423272f5b8
5
+ SHA512:
6
+ metadata.gz: 2fa8a4ae37e61c00080f15f2c1e4fe26eab51cca0bfe47edf224588e28a943e2824a1051d836df9816d44dd4cd31bd4af3c5a01b408257a851038c4d13c6eca4
7
+ data.tar.gz: ef4fa41fe57f18398cc771f60bad5110b68655266402c661078723eba1de7c93ef398dd80b2f5080ba214c950215a0c82498c1eebbd1d977e2ceade6feea230b
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+ script: 'bundle exec rake'
4
+ rvm:
5
+ - 2.1.2
6
+ services:
7
+ - mongodb
8
+
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - tomas.celizna@gmail.com
13
+ on_failure: change
14
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid_recurring.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :minitest do
2
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
3
+ watch(%r{^test/.+_test\.rb$})
4
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tomas Celizna
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # MongoidRecurring
2
+
3
+ [![Build Status](https://travis-ci.org/tomasc/mongoid_recurring.svg)](https://travis-ci.org/tomasc/mongoid_recurring) [![Gem Version](https://badge.fury.io/rb/mongoid_recurring.svg)](http://badge.fury.io/rb/mongoid_recurring) [![Coverage Status](https://img.shields.io/coveralls/tomasc/mongoid_recurring.svg)](https://coveralls.io/r/tomasc/mongoid_recurring)
4
+
5
+ Recurring date time fields for Mongoid models, using [IceCube](https://github.com/seejohnrun/ice_cube/).
6
+
7
+ When included in a model, this gem expands the recurring rules set of an `IceCube` schedule on save into an array of embedded `MongoidRecurring::Occurence` models.
8
+
9
+ It also adds definitions of several scopes that allow for convenient querying of models stored in the db.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'mongoid_recurring'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install mongoid_recurring
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ class MyModel
31
+ include Mongoid::Document
32
+ include MongoidRecurring::HasRecurringFields
33
+ has_recurring_fields
34
+ end
35
+ ```
36
+
37
+ Which will then add `dtstart`, `dtend`, `all_day`, `schedule` and `schedule_dtend` fields to the model.
38
+
39
+ The model will generate all occurrences on before save, and stores them as embedded `MongoidRecurring::Occurrence` documents in the `:occurrences` embedded relation.
40
+
41
+ A scope named `.for_datetime_range` can be then used to query for documents with occurrences in specified DateTime range:
42
+
43
+ ```ruby
44
+ MyModel.for_datetime_range( Date.today, Date.today+1.week )
45
+ ```
46
+
47
+ ## Configuration
48
+
49
+ By default, when `schedule_dtend` is not specified, the `:occurrences` are populated for 1 year in advance. This duration can be configured as follows:
50
+
51
+ has_recurring_fields schedule_duration: 2.weeks
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/[my-github-username]/mongoid_recurring/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mongoid_recurring"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,54 @@
1
+ require 'mongoid'
2
+ require 'mongoid_ice_cube_extension'
3
+
4
+ module MongoidRecurring
5
+ module HasRecurringFields
6
+
7
+ def self.included base
8
+ base.extend ClassMethods
9
+ base.class_eval do
10
+ @@schedule_duration = 1.year
11
+ end
12
+ end
13
+
14
+ # =====================================================================
15
+
16
+ module ClassMethods
17
+ def has_recurring_fields options={}
18
+ @@schedule_duration = options[:schedule_duration] if options[:schedule_duration].present?
19
+
20
+ field :dtstart, type: DateTime
21
+ field :dtend, type: DateTime
22
+ field :all_day, type: Boolean, default: false
23
+
24
+ field :schedule, type: MongoidIceCubeExtension::Schedule
25
+ field :schedule_dtend, type: DateTime
26
+
27
+ embeds_many :occurrences, class_name: 'MongoidRecurring::Occurence', order: :dtstart.asc
28
+
29
+ validates :dtstart, presence: true
30
+
31
+ before_save :expand_schedule_to_occurrences
32
+
33
+ scope :for_datetime_range, -> (dtstart, dtend) {
34
+ where( occurrences: { "$elemMatch" => { :dtstart.gte => dtstart.to_datetime, :dtend.lte => dtend.to_datetime } } )
35
+ }
36
+ end
37
+ end
38
+
39
+ private # =============================================================
40
+
41
+ def expand_schedule_to_occurrences
42
+ self.occurrences = schedule.present? ? occurrences_from_schedule : occurrences_from_model
43
+ end
44
+
45
+ def occurrences_from_schedule
46
+ schedule.occurrences(schedule_dtend || (schedule.start_time + @@schedule_duration)).collect { |o| MongoidRecurring::Occurence.new( dtstart: o.start_time, dtend: o.end_time, all_day: all_day ) }
47
+ end
48
+
49
+ def occurrences_from_model
50
+ [ MongoidRecurring::Occurence.new( dtstart: dtstart, dtend: dtend, all_day: all_day ) ]
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,38 @@
1
+ require 'mongoid'
2
+
3
+ module MongoidRecurring
4
+ class Occurence
5
+ include Mongoid::Document
6
+
7
+ field :dtstart, type: DateTime
8
+ field :dtend, type: DateTime
9
+
10
+ attr_accessor :all_day
11
+
12
+ embedded_in :schedule, class_name: 'MongoidRecurring::Occurence'
13
+
14
+ validates :dtstart, presence: true
15
+ validates :dtend, presence: true
16
+
17
+ before_save :set_dtend
18
+ before_save :adjust_dates_for_all_day
19
+
20
+ # =====================================================================
21
+
22
+ def all_day?
23
+ self.all_day == true
24
+ end
25
+
26
+ private # =============================================================
27
+
28
+ def set_dtend
29
+ self.dtend ||= dtstart
30
+ end
31
+
32
+ def adjust_dates_for_all_day
33
+ return unless all_day?
34
+ self.dtstart = dtstart.beginning_of_day
35
+ self.dtend = dtend.end_of_day
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module MongoidRecurring
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'active_support/core_ext/date'
2
+ require 'active_support/core_ext/date_time'
3
+
4
+ require "mongoid_recurring/occurence"
5
+ require "mongoid_recurring/has_recurring_fields"
6
+
7
+ require "mongoid_recurring/version"
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongoid_recurring/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongoid_recurring"
8
+ spec.version = MongoidRecurring::VERSION
9
+ spec.authors = ["Tomáš Celizna"]
10
+ spec.email = ["tomas.celizna@gmail.com"]
11
+
12
+ spec.summary = %q{Recurring date time fields for Mongoid models.}
13
+ spec.homepage = "https://github.com/tomasc/mongoid_recurring"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport", "> 3.0"
22
+ spec.add_dependency "ice_cube"
23
+ spec.add_dependency "mongoid", "~> 5.0"
24
+ spec.add_dependency "mongoid_ice_cube_extension", ">= 0.1.1"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.6"
27
+ spec.add_development_dependency "coveralls"
28
+ spec.add_development_dependency "database_cleaner"
29
+ spec.add_development_dependency "guard"
30
+ spec.add_development_dependency "guard-minitest"
31
+ spec.add_development_dependency "minitest"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_recurring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomáš Celizna
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ice_cube
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mongoid_ice_cube_extension
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: database_cleaner
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-minitest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: minitest
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '10.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '10.0'
167
+ description:
168
+ email:
169
+ - tomas.celizna@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".coveralls.yml"
175
+ - ".gitignore"
176
+ - ".travis.yml"
177
+ - Gemfile
178
+ - Guardfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/setup
184
+ - lib/mongoid_recurring.rb
185
+ - lib/mongoid_recurring/has_recurring_fields.rb
186
+ - lib/mongoid_recurring/occurence.rb
187
+ - lib/mongoid_recurring/version.rb
188
+ - mongoid_recurring.gemspec
189
+ homepage: https://github.com/tomasc/mongoid_recurring
190
+ licenses:
191
+ - MIT
192
+ metadata: {}
193
+ post_install_message:
194
+ rdoc_options: []
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ requirements: []
208
+ rubyforge_project:
209
+ rubygems_version: 2.4.8
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: Recurring date time fields for Mongoid models.
213
+ test_files: []