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 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.2
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)
@@ -4,9 +4,7 @@ class Account
4
4
 
5
5
  field :period, :type => ::Timespan, :between => true
6
6
 
7
- delegate :start_date, to: :period
8
-
9
- timespan_setters :period
7
+ timespan_methods :period
10
8
 
11
9
  def self.create_it! duration
12
10
  t = ::Timespan.new(duration: duration)
@@ -50,6 +50,10 @@ describe TimeSpan do
50
50
  subject.period_start = tomorrow
51
51
  end
52
52
 
53
+ specify do
54
+ subject.start_date.should == subject.period.start_date
55
+ end
56
+
53
57
  specify do
54
58
  Date.parse(subject.start_date.to_s).should == tomorrow
55
59
  end
data/timespan.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "timespan"
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
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.2
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: -2120967004770595531
250
+ hash: -3678905643700355626
251
251
  required_rubygems_version: !ruby/object:Gem::Requirement
252
252
  none: false
253
253
  requirements: