timespan 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +17 -0
- data/VERSION +1 -1
- data/lib/timespan/mongoid/timespanned.rb +9 -0
- data/spec/timespan/mongoid/models/account_3x.rb +1 -3
- data/spec/timespan/mongoid/mongoid_timespan_spec.rb +4 -0
- data/timespan.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -116,10 +116,20 @@ require 'timespan/mongoid'
|
|
116
116
|
|
117
117
|
class Account
|
118
118
|
include Mongoid::Document
|
119
|
+
include Mongoid::Timespanned
|
120
|
+
|
119
121
|
field :period, :type => TimeSpan
|
122
|
+
|
123
|
+
timespan_methods :period
|
120
124
|
end
|
121
125
|
```
|
122
126
|
|
127
|
+
`Mongoid::Timespanned` adds the following class level macros:
|
128
|
+
|
129
|
+
* `timespan_methods name`
|
130
|
+
* `timespan_delegates name`
|
131
|
+
* `timespan_setters name`
|
132
|
+
|
123
133
|
Usage example:
|
124
134
|
|
125
135
|
```ruby
|
@@ -130,6 +140,13 @@ account.period.end_date
|
|
130
140
|
account.period.days
|
131
141
|
account.period.duration # => Duration
|
132
142
|
|
143
|
+
account.period_start = tomorrow
|
144
|
+
account.period_end = 5.days.from_now
|
145
|
+
|
146
|
+
account.start_date == tomorrow
|
147
|
+
account.end_date == tomorrow
|
148
|
+
```
|
149
|
+
|
133
150
|
## Searching periods
|
134
151
|
|
135
152
|
```ruby
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
@@ -3,6 +3,15 @@ module Mongoid
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
+
def timespan_methods name
|
7
|
+
timespan_delegates name
|
8
|
+
timespan_setters name
|
9
|
+
end
|
10
|
+
|
11
|
+
def timespan_delegates name = :period
|
12
|
+
delegate :time_left, :duration, :start_date, :end_date, to: name
|
13
|
+
end
|
14
|
+
|
6
15
|
def timespan_setters name = :period
|
7
16
|
define_method :"#{name}_start=" do |date|
|
8
17
|
self.send "#{name}=", ::Timespan.new(start_date: date, end_date: self.send(name).end_date)
|
data/timespan.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timespan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -247,7 +247,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
247
247
|
version: '0'
|
248
248
|
segments:
|
249
249
|
- 0
|
250
|
-
hash: -
|
250
|
+
hash: -3678905643700355626
|
251
251
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
252
252
|
none: false
|
253
253
|
requirements:
|