datetime_helper 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDMxOTMyOTgzYjIyMGQ1MDhlODBkN2U3YTJjNTYzMTkwYzFlOTQ4OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmEwMzBjOTM3NGI4MmM3YTI1MjU4NDNjYWM0MjlhNGYwMWFkYWQ2YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTk0OWY0YmU1NzI2OGY1M2M2NWVlNGQzM2MzZDEyY2I3NjhmYWRhODQwZjNl
|
10
|
+
NDEyMWIxMGY4ZGY4YzVhYTA3ZGJlNjkwZWY3ZWJlZTM1ZmI1NzIyYjYxOTFl
|
11
|
+
YjNlZWE4MTFmMzQ3NWFhODhkYmZmMzUyNjk4ZjBhZWMwMTBjNjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Mjg0M2MxNmI3NGJkZWU5YzY4ZmMzYTFmNWQzNmIwM2FmMDU0YmY1ZmJlYzEx
|
14
|
+
YTlkOTU2NjU5NjY2YTNkM2Q4OWYzNzNkNzI2MjdhNzc5ZDU2YmVmMzEyYWZj
|
15
|
+
ZTI5MDM1ZjExY2I2ZjlhYThhYWZjYmM3OWNkN2I5ZGU5ODc4OTQ=
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ A collection of useful utilities for projects that have to deal with dates, time
|
|
7
7
|
1. A base method called `is_zulu_time?`,
|
8
8
|
2. `rspec` matchers `be_zulu_time`, `be_an_iso_formatted_date`, and `be_an_iso_formatted_time`
|
9
9
|
3. An `ActiveModel` validator called `zulu_time`, and
|
10
|
-
4.
|
10
|
+
4. `ActiveModel::Serializer` helper methods called `enforce_zulu_time` and `enforce_iso8601_date` that allow formatting and aliasing.
|
11
11
|
|
12
12
|
Each feature can be required individually so you can use the `rspec` matcher, `ActiveModel` validator, or `ActiveModel::Serializer` helper in isolation.
|
13
13
|
|
@@ -99,8 +99,11 @@ extend DatetimeHelper::Serialisers
|
|
99
99
|
|
100
100
|
enforce_zulu_time :updated_at
|
101
101
|
enforce_iso8601_date :enable_date
|
102
|
+
enforce_zulu_time :published_at, :published_date
|
102
103
|
```
|
103
104
|
|
105
|
+
The last case will also alias the api attribute `published_at` to the table attribute `published_date`.
|
106
|
+
|
104
107
|
or if you have a bunch of 'em
|
105
108
|
|
106
109
|
```ruby
|
@@ -147,3 +150,7 @@ The `Datetime Helper` is © 2015 Westfield Labs and is available for use under t
|
|
147
150
|
|`1.0.0`| Cleaned up for first official release |
|
148
151
|
|`1.0.1`| Enhanced matchers, and validator |
|
149
152
|
|`1.0.2`| Add iso8601 date format for serializers |
|
153
|
+
|`1.0.3`| Change enforce_iso8601_date to work with |
|
154
|
+
| | date-time objects |
|
155
|
+
|`1.0.4`| Anchor strings in RSpec matchers |
|
156
|
+
|`1.0.5`| Add aliasing to serializer formatting |
|
data/contributing.md
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
"Brother I got a 12 step plan for you…" - The Alabama Three
|
4
4
|
|
5
|
-
0. Raise an issue in this project
|
5
|
+
0. Raise an issue in this project outlining the change you'd like to make. You'll need the `issue_number`
|
6
6
|
1. Fork this project into your own Github account
|
7
7
|
2. Create your feature branch (`git checkout -b {issue_number}_my-new-feature`)
|
8
8
|
4. Push to the branch (`git push -u origin {issue_number}_my-new-feature`)
|
9
|
-
5. Write
|
9
|
+
5. Write RSpec tests to formalise the outcomes of your change
|
10
10
|
6. write the code to implement the changes, ensuring that the tests eventually pass
|
11
11
|
7. Commit your changes (`git commit -am '{issue_number} Added some feature'`)
|
12
12
|
8. Push to the branch (`git push -u origin my-new-feature`)
|
13
13
|
9. Create a new Pull Request using Github's built-in mechanisms.
|
14
14
|
10. Wait for a code review to come back, or an approval.
|
15
|
-
11. Either go back and fix whatever the reviewers recommend, or watch and smile as your PR gets merged in and you become part of
|
15
|
+
11. Either go back and fix whatever the reviewers recommend, or watch and smile as your PR gets merged in and you become part of software development history.
|
@@ -2,16 +2,18 @@ module DatetimeHelper
|
|
2
2
|
module Serialisers
|
3
3
|
|
4
4
|
# Enforces that a DateTime is serialised as zulu time format
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# Allow optional aliasing
|
6
|
+
def enforce_zulu_time(api_attribute, table_column = api_attribute)
|
7
|
+
define_method(api_attribute) do
|
8
|
+
object.send(table_column).utc.iso8601 unless object.send(table_column).nil?
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
12
|
# Enforces that a Date is serialized as iso8601 format
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
# Allow optional aliasing
|
14
|
+
def enforce_iso8601_date(api_attribute, table_column = api_attribute)
|
15
|
+
define_method(api_attribute) do
|
16
|
+
object.send(table_column).strftime('%F') unless object.send(table_column).nil?
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -3,11 +3,14 @@ require "datetime_helper/active_model_serialiser"
|
|
3
3
|
|
4
4
|
class TestSerialiser < ActiveModel::Serializer
|
5
5
|
extend DatetimeHelper::Serialisers
|
6
|
-
attributes :updated_at, :enabled_date, :enabled_time
|
6
|
+
attributes :updated_at, :enabled_date, :enabled_time,
|
7
|
+
:aliased_time, :aliased_date
|
7
8
|
|
8
9
|
enforce_zulu_time :updated_at
|
9
10
|
enforce_iso8601_date :enabled_date
|
10
11
|
enforce_iso8601_date :enabled_time
|
12
|
+
enforce_zulu_time :aliased_time, :updated_at
|
13
|
+
enforce_iso8601_date :aliased_date, :enabled_date
|
11
14
|
end
|
12
15
|
|
13
16
|
class TestItemNoTime
|
@@ -35,27 +38,32 @@ describe DatetimeHelper::Serialisers do
|
|
35
38
|
context 'with a UTC time' do
|
36
39
|
let(:item) { TestItem.new }
|
37
40
|
it { expect(subject[:updated_at]).to be_zulu_time }
|
41
|
+
it { expect(subject[:aliased_time]).to eq subject[:updated_at] }
|
38
42
|
end
|
39
43
|
|
40
44
|
context 'with a local time' do
|
41
45
|
let(:item) { TestItem.new updated_at: Time.now.getlocal }
|
42
46
|
it { expect(subject[:updated_at]).to be_zulu_time }
|
47
|
+
it { expect(subject[:aliased_time]).to eq subject[:updated_at] }
|
43
48
|
end
|
44
49
|
|
45
50
|
context 'with a nil time' do
|
46
51
|
let(:item) { TestItemNoTime.new }
|
47
52
|
it { expect(subject[:updated_at]).to be_nil}
|
53
|
+
it { expect(subject[:aliased_time]).to eq subject[:updated_at] }
|
48
54
|
end
|
49
55
|
|
50
56
|
context 'with a date' do
|
51
57
|
let(:item) { TestItem.new }
|
52
58
|
|
53
59
|
it { expect(subject[:enabled_date]).to be_an_iso_formatted_date }
|
60
|
+
it { expect(subject[:aliased_date]).to eq subject[:enabled_date] }
|
54
61
|
end
|
55
62
|
|
56
63
|
context 'with a nil date' do
|
57
64
|
let(:item) { TestItemNoTime.new }
|
58
65
|
it { expect(subject[:enabled_date]).to be_nil}
|
66
|
+
it { expect(subject[:aliased_date]).to eq subject[:enabled_date] }
|
59
67
|
end
|
60
68
|
|
61
69
|
context 'with a date-time' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datetime_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- davesag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|