month-serializer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +35 -0
- data/.travis.yml +59 -0
- data/Appraisals +29 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +155 -0
- data/Rakefile +28 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/jruby_1.7.26.gemfile +16 -0
- data/gemfiles/jruby_9.1.9.0.gemfile +15 -0
- data/gemfiles/jruby_9.2.0.0.gemfile +15 -0
- data/gemfiles/jruby_head.gemfile +15 -0
- data/gemfiles/ruby_1.9.3_p551.gemfile +16 -0
- data/gemfiles/ruby_2.0.0_p648.gemfile +16 -0
- data/gemfiles/ruby_2.1.10.gemfile +15 -0
- data/gemfiles/ruby_2.2.10.gemfile +16 -0
- data/gemfiles/ruby_2.3.7.gemfile +16 -0
- data/gemfiles/ruby_2.4.4.gemfile +16 -0
- data/gemfiles/ruby_2.5.1.gemfile +16 -0
- data/gemfiles/ruby_head.gemfile +16 -0
- data/lib/month/serializer.rb +110 -0
- data/lib/month/serializer/version.rb +5 -0
- data/month-serializer.gemspec +34 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8d260a155dfc1e0284cb733cdcbafa22098ed76ea04e3562f7c2536316710e73
|
4
|
+
data.tar.gz: 7194191242d482a95a915fb39115476ea4bc33743cd9750cb05e73f139b17d76
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96bc4e94b3c377588f6cb6d8f8210cde63d0f443d56503463db9a79d7c048d37f295277788d5cfb8423ecb36717cf9b64e937af6f5cfea24d50566bb15112f04
|
7
|
+
data.tar.gz: c29839a15c8f1b0be1a806a977bfce968fe83297f42be61e4ca53d3a2e3177ccce29cd2d0289ccb4feb5ebb2220494a6b822c49e500f90c029bc48326299ef13
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true # Display the name of the failing cops
|
3
|
+
Exclude:
|
4
|
+
- 'gemfiles/vendor/**/*'
|
5
|
+
- 'vendor/**/*'
|
6
|
+
|
7
|
+
Metrics/BlockLength:
|
8
|
+
ExcludedMethods:
|
9
|
+
- context
|
10
|
+
- describe
|
11
|
+
- it
|
12
|
+
- shared_context
|
13
|
+
- shared_examples
|
14
|
+
- shared_examples_for
|
15
|
+
- namespace
|
16
|
+
- draw
|
17
|
+
|
18
|
+
Metrics/LineLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/HashSyntax:
|
22
|
+
EnforcedStyle: hash_rockets
|
23
|
+
|
24
|
+
Style/Lambda:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/PercentLiteralDelimiters:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/SymbolArray:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
# Enable when drop support for Ruby < 2
|
34
|
+
Style/ExpandPathArguments:
|
35
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- JRUBY_OPTS="-Xcli.debug=true --debug"
|
4
|
+
- CC_TEST_REPORTER_ID=574f3037b6025eaa588f8cf616243ffe4f0be7fd3d8ab6097f3e76bce407eabf
|
5
|
+
|
6
|
+
before_script:
|
7
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
8
|
+
- chmod +x ./cc-test-reporter
|
9
|
+
- ./cc-test-reporter before-build
|
10
|
+
|
11
|
+
script:
|
12
|
+
- bundle exec rspec
|
13
|
+
|
14
|
+
after_script:
|
15
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
16
|
+
|
17
|
+
before_install:
|
18
|
+
- gem update --system
|
19
|
+
- gem install bundler
|
20
|
+
|
21
|
+
install:
|
22
|
+
- bundle install
|
23
|
+
|
24
|
+
bundler_args: --no-deployment --jobs 3 --retry 3
|
25
|
+
|
26
|
+
cache: bundler
|
27
|
+
|
28
|
+
language: ruby
|
29
|
+
sudo: false
|
30
|
+
matrix:
|
31
|
+
allow_failures:
|
32
|
+
- rvm: jruby-head
|
33
|
+
- rvm: ruby-head
|
34
|
+
fast_finish: true
|
35
|
+
include:
|
36
|
+
- rvm: 1.9.3-p551
|
37
|
+
gemfile: gemfiles/ruby_1.9.3_p551.gemfile
|
38
|
+
- rvm: 2.0.0-p648
|
39
|
+
gemfile: gemfiles/ruby_2.0.0_p648.gemfile
|
40
|
+
- rvm: 2.1.10
|
41
|
+
gemfile: gemfiles/ruby_2.1.10.gemfile
|
42
|
+
- rvm: 2.2.10
|
43
|
+
gemfile: gemfiles/ruby_2.2.10.gemfile
|
44
|
+
- rvm: 2.3.7
|
45
|
+
gemfile: gemfiles/ruby_2.3.7.gemfile
|
46
|
+
- rvm: 2.4.4
|
47
|
+
gemfile: gemfiles/ruby_2.4.4.gemfile
|
48
|
+
- rvm: 2.5.1
|
49
|
+
gemfile: gemfiles/ruby_2.5.1.gemfile
|
50
|
+
- rvm: ruby-head
|
51
|
+
gemfile: gemfiles/ruby_head.gemfile
|
52
|
+
- rvm: jruby-1.7.26
|
53
|
+
gemfile: gemfiles/jruby_1.7.26.gemfile
|
54
|
+
- rvm: jruby-9.1.9.0
|
55
|
+
gemfile: gemfiles/jruby_9.1.9.0.gemfile
|
56
|
+
- rvm: jruby-9.2.0.0
|
57
|
+
gemfile: gemfiles/jruby_9.2.0.0.gemfile
|
58
|
+
- rvm: jruby-head
|
59
|
+
gemfile: gemfiles/jruby_head.gemfile
|
data/Appraisals
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
appraise 'jruby-1.7.26' do
|
2
|
+
end
|
3
|
+
|
4
|
+
appraise 'ruby-1.9.3-p551' do
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'ruby-2.0.0-p648' do
|
8
|
+
end
|
9
|
+
|
10
|
+
appraise 'ruby-2.1.10' do
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'ruby-2.2.10' do
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise 'jruby-9.1.9.0' do
|
17
|
+
end
|
18
|
+
|
19
|
+
appraise 'ruby-2.3.7' do
|
20
|
+
end
|
21
|
+
|
22
|
+
appraise 'ruby-2.4.4' do
|
23
|
+
end
|
24
|
+
|
25
|
+
appraise 'ruby-2.5.1' do
|
26
|
+
end
|
27
|
+
|
28
|
+
appraise 'jruby-9.2.0.0' do
|
29
|
+
end
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at peter.boling@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018 Peter H. Boling of RailsBling.com
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Month::Serializer
|
2
|
+
|
3
|
+
**Integer Serialization Plugin for [Month Gem](https://github.com/timcraft/month)**
|
4
|
+
|
5
|
+
Allows you to convert [`Month` objects](https://github.com/timcraft/month/blob/master/lib/month.rb) to `Integer`, and vice versa. This is useful for serializing Months into other data structures, like `String`, or to pass values in `JSON`, or send as parameters to Resque / Sidekiq jobs (which parameters are [only compatible with simple JSON data types](https://github.com/mperham/sidekiq/wiki/The-Basics#client). Neither `Date` or `Month` can serialize properly to Resque/Sidekiq jobs.
|
6
|
+
|
7
|
+
| Project | Month::Serializer |
|
8
|
+
|------------------------ | ----------------------- |
|
9
|
+
| gem name | [month-serializer](https://rubygems.org/gems/month-serializer) |
|
10
|
+
| license | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) |
|
11
|
+
| download rank | [![Downloads Today](https://img.shields.io/gem/rd/month-serializer.svg)](https://github.com/pboling/month-serializer) |
|
12
|
+
| version | [![Version](https://img.shields.io/gem/v/month-serializer.svg)](https://rubygems.org/gems/month-serializer) |
|
13
|
+
| dependencies | [![Depfu](https://badges.depfu.com/badges/9b99dea566c438afe054a94d464e98ea/count.svg)](https://depfu.com/github/pboling/month-serializer?project_id=6003) |
|
14
|
+
| continuous integration | [![Build Status](https://travis-ci.org/pboling/month-serializer.svg?branch=master)](https://travis-ci.org/pboling/month-serializer) |
|
15
|
+
| test coverage | [![Test Coverage](https://api.codeclimate.com/v1/badges/50241bf0d9c78bcce69e/test_coverage)](https://codeclimate.com/github/pboling/month-serializer/test_coverage) |
|
16
|
+
| maintainability | [![Maintainability](https://api.codeclimate.com/v1/badges/50241bf0d9c78bcce69e/maintainability)](https://codeclimate.com/github/pboling/month-serializer/maintainability) |
|
17
|
+
| code triage | [![Open Source Helpers](https://www.codetriage.com/pboling/month-serializer/badges/users.svg)](https://www.codetriage.com/pboling/month-serializer) |
|
18
|
+
| homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] |
|
19
|
+
| documentation | [on RDoc.info][documentation] |
|
20
|
+
| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌍 🌎 🌏][peterboling], [🍚][refugees], [➕][gplus], [👼][angellist], [🐛][topcoder], [:shipit:][coderwall], [![Tweet Peter](https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow)][twitter] |
|
21
|
+
|
22
|
+
### Why use Month instead of Date or Time?
|
23
|
+
|
24
|
+
- Month is lighter weight.
|
25
|
+
- There are many situations where having Months incrementable by 1 is useful
|
26
|
+
- e.g. Directly mappable to iteration index
|
27
|
+
- It facilitates month-based math.
|
28
|
+
- Adding a day when a day is not relevant, such as for data with a 1 month resolution, can result in very overcomplicated systems that try to work around or ignore the stray days.
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
Add this line to your application's Gemfile:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem 'month-serializer'
|
36
|
+
```
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install month-serializer
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
Add this to the bootstrapping process of your app, somewhere after the [`month` gem](https://github.com/timcraft/month) is loaded.
|
49
|
+
In Rails, `config/initializers/month-serializer.rb` would be perfect, but Rails is not required.
|
50
|
+
|
51
|
+
````ruby
|
52
|
+
Month.send(:include, Month::Serializer)
|
53
|
+
````
|
54
|
+
|
55
|
+
This spec below, copied from the actual test suite, makes usage pretty clear. Note how the serialized Months as integer increment by one. If you think about counting time by months this makes sense. We often speak this way about babies, an 18 month old, or 24 month old.
|
56
|
+
|
57
|
+
How old is the Common Era right now? About 24.2k months! Is a millenimonth, millimes, or kilomonth, a thing? The Common Era is roughly 24 kilomonths old. 😆 And Neanderthal man went extinct about 471 kilomonths ago.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
{
|
61
|
+
-471359 => Month.new(-39280, 1), # hist: Extinction of Neanderthal
|
62
|
+
24201 => Month.new(2016, 9),
|
63
|
+
24202 => Month.new(2016, 10),
|
64
|
+
# ...
|
65
|
+
24214 => Month.new(2017, 10),
|
66
|
+
24215 => Month.new(2017, 11),
|
67
|
+
# ...
|
68
|
+
24227 => Month.new(2018, 11),
|
69
|
+
24228 => Month.new(2018, 12)
|
70
|
+
}.each do |k, v|
|
71
|
+
context "#{k} => #{v}" do
|
72
|
+
it "Month converts to #{k}" do
|
73
|
+
expect(v.to_i).to eq(k) # to_i is added by this gem!
|
74
|
+
end
|
75
|
+
context 'round trip' do
|
76
|
+
it "can load #{k} to #{v}" do
|
77
|
+
expect(Month.load(k)).to eq(v) # load is added by this gem!
|
78
|
+
end
|
79
|
+
it "can dump #{v} to #{k}" do
|
80
|
+
expect(Month.dump(v)).to eq(k) # dump is added by this gem!
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
90
|
+
|
91
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
92
|
+
|
93
|
+
## Authors
|
94
|
+
|
95
|
+
[Peter H. Boling][peterboling] of [Rails Bling][railsbling] is the author.
|
96
|
+
|
97
|
+
## Contributors
|
98
|
+
|
99
|
+
See the [Network View](https://github.com/pboling/month-serializer/network) and the [CHANGELOG](https://github.com/pboling/month-serializer/blob/master/CHANGELOG.md)
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
1. Fork it
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
106
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
107
|
+
5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
108
|
+
6. Create new Pull Request
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pboling/anonymous_active_record. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
111
|
+
|
112
|
+
## Code of Conduct
|
113
|
+
|
114
|
+
Everyone interacting in the AnonymousActiveRecord project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pboling/anonymous_active_record/blob/master/CODE_OF_CONDUCT.md).
|
115
|
+
|
116
|
+
## Versioning
|
117
|
+
|
118
|
+
This library aims to adhere to [Semantic Versioning 2.0.0][semver].
|
119
|
+
Violations of this scheme should be reported as bugs. Specifically,
|
120
|
+
if a minor or patch version is released that breaks backward
|
121
|
+
compatibility, a new version should be immediately released that
|
122
|
+
restores compatibility. Breaking changes to the public API will
|
123
|
+
only be introduced with new major versions.
|
124
|
+
|
125
|
+
As a result of this policy, you can (and should) specify a
|
126
|
+
dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
|
127
|
+
|
128
|
+
For example in a `Gemfile`:
|
129
|
+
|
130
|
+
gem 'month-serializer', '~> 1.0', group: :test
|
131
|
+
|
132
|
+
or in a `gemspec`
|
133
|
+
|
134
|
+
spec.add_development_dependency 'month-serializer', '~> 1.0'
|
135
|
+
|
136
|
+
## Legal
|
137
|
+
|
138
|
+
* MIT License - See [LICENSE][license] file in this project [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
|
139
|
+
|
140
|
+
* Copyright (c) 2018 [Peter H. Boling][peterboling] of [Rails Bling][railsbling]
|
141
|
+
|
142
|
+
[semver]: http://semver.org/
|
143
|
+
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
144
|
+
[documentation]: http://rdoc.info/github/pboling/month-serializer/frames
|
145
|
+
[homepage]: https://github.com/pboling/month-serializer
|
146
|
+
[blogpage]: http://www.railsbling.com/tags/month-serializer/
|
147
|
+
[license]: LICENSE
|
148
|
+
[railsbling]: http://www.railsbling.com
|
149
|
+
[peterboling]: https://about.me/peter.boling
|
150
|
+
[refugees]: https://www.crowdrise.com/helprefugeeswithhopefortomorrowliberia/fundraiser/peterboling
|
151
|
+
[gplus]: https://plus.google.com/+PeterBoling/posts
|
152
|
+
[topcoder]: https://www.topcoder.com/members/pboling/
|
153
|
+
[angellist]: https://angel.co/peter-boling
|
154
|
+
[coderwall]: http://coderwall.com/pboling
|
155
|
+
[twitter]: http://twitter.com/galtzo
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
begin
|
3
|
+
require 'wwtd/tasks'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'failed to load wwtd'
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
rescue LoadError
|
12
|
+
# puts "failed to load wwtd or rspec, probably because bundled --without-development"
|
13
|
+
task :spec do
|
14
|
+
warn 'rspec is disabled'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
task :test => :spec
|
18
|
+
|
19
|
+
begin
|
20
|
+
require 'rubocop/rake_task'
|
21
|
+
RuboCop::RakeTask.new
|
22
|
+
rescue LoadError
|
23
|
+
task :rubocop do
|
24
|
+
warn 'RuboCop is disabled'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => [:test, :rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'month/serializer'
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
# Some changes to defaults make older version config incompatible with newer version config
|
11
|
+
# gem "rubocop", "~> 0.41.2"
|
12
|
+
gem 'rake'
|
13
|
+
gem 'rspec'
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
# Some changes to defaults make older version config incompatible with newer version config
|
11
|
+
# gem "rubocop", "~> 0.41.2"
|
12
|
+
gem 'rake'
|
13
|
+
gem 'rspec'
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
# Some changes to defaults make older version config incompatible with newer version config
|
11
|
+
# gem "rubocop", "~> 0.41.2"
|
12
|
+
gem 'rake'
|
13
|
+
gem 'rspec'
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop', '~> 0.52.1'
|
13
|
+
gem 'simplecov', '~> 0', :require => false
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop', '~> 0.52.1'
|
13
|
+
gem 'simplecov', '~> 0', :require => false
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop', '~> 0.52.1'
|
13
|
+
gem 'simplecov', '~> 0', :require => false
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop', '~> 0.52.1'
|
13
|
+
gem 'simplecov', '~> 0', :require => false
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop', '~> 0.52.1'
|
13
|
+
gem 'simplecov', '~> 0', :require => false
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec :path => '../'
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'month/serializer/version'
|
2
|
+
|
3
|
+
# Eternal Gems
|
4
|
+
require 'month'
|
5
|
+
|
6
|
+
class Month
|
7
|
+
module Serializer
|
8
|
+
def self.included(base)
|
9
|
+
puts "including #{self} into #{base}"
|
10
|
+
base.extend ClassMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def load(month_as_integer)
|
15
|
+
raise_load_error(month_as_integer) unless month_as_integer.is_a?(Integer)
|
16
|
+
year, number = month_as_integer.divmod(12)
|
17
|
+
# A zero month actually points to December of the previous year,
|
18
|
+
# because when dividing by 12, possible remainders are 0 - 11
|
19
|
+
# and we need months 1 - 12
|
20
|
+
#
|
21
|
+
# NOTE ON ZERO:
|
22
|
+
#
|
23
|
+
# There is no Year Zero in the anno domini system.
|
24
|
+
# See: https://en.wikipedia.org/wiki/Year_zero
|
25
|
+
#
|
26
|
+
# But ISO 8601:2004 does have a year zero, and it coincides with Gregorian year 1 BC.
|
27
|
+
# See: https://en.wikipedia.org/wiki/ISO_8601
|
28
|
+
#
|
29
|
+
# And what about Ruby?
|
30
|
+
#
|
31
|
+
# >> Date.new(0, 1, 1)
|
32
|
+
# => #<Date: 0000-01-01 ((1721058j,0s,0n),+0s,2299161j)>
|
33
|
+
# >> Date.new(0, 1, 1) << 1
|
34
|
+
# => #<Date: -0001-12-01 ((1721027j,0s,0n),+0s,2299161j)>
|
35
|
+
# >> Date.new(0, 1, 1) >> 12
|
36
|
+
# => #<Date: 0001-01-01 ((1721424j,0s,0n),+0s,2299161j)>
|
37
|
+
# >> Date.new(2018, 1, 1) >> 12
|
38
|
+
# => #<Date: 2019-01-01 ((2458485j,0s,0n),+0s,2299161j)>
|
39
|
+
#
|
40
|
+
# We want a line of integers that represent months that are unbroken
|
41
|
+
# steps of distance 1, so we have to have a Month 0
|
42
|
+
#
|
43
|
+
# Month -24 is December, Year -3 # -24.divmod(12) => [-2, 0] # year -= 1, number = 12
|
44
|
+
# Month -23 is January, Year -2 # -23.divmod(12) => [-2, 1] # no mod
|
45
|
+
# Month -12 is December, Year -2 # -12.divmod(12) => [-1, 0] # year -= 1, number = 12
|
46
|
+
# Month -11 is January, Year -1 # -11.divmod(12) => [-1, 1] # no mod
|
47
|
+
# Month -10 is February, Year -1 # -10.divmod(12) => [-1, 2] # no mod
|
48
|
+
# Month -2 is October, Year -1 # -2.divmod(12) => [-1, 10] # no mod
|
49
|
+
# Month -1 is November, Year -1 # -1.divmod(12) => [-1, 11] # no mod
|
50
|
+
# Month 0 is December, Year -1 # 0.divmod(12) => [0, 0] # year -= 1, number = 12
|
51
|
+
# Month 1 is January, Year 0 # 1.divmod(12) => [0, 1] # no mod
|
52
|
+
# Month 2 is February, Year 0 # 2.divmod(12) => [0, 2] # no mod
|
53
|
+
# Month 11 is November, Year 0 # 11.divmod(12) => [0, 11] # no mod
|
54
|
+
# Month 12 is December, Year 0 # 12.divmod(12) => [1, 0] # year -= 1, number = 12
|
55
|
+
# Month 13 is January, Year 1 # 13.divmod(12) => [1, 1] # no mod
|
56
|
+
# Month 23 is November, Year 1 # 23.divmod(12) => [1, 11] # no mod
|
57
|
+
# Month 24 is December, Year 1 # 24.divmod(12) => [2, 0] # year -= 1, number = 12
|
58
|
+
# Month 25 is January, Year 2 # 25.divmod(12) => [2, 1] # no mod
|
59
|
+
if number.zero?
|
60
|
+
number = 12
|
61
|
+
year -= 1
|
62
|
+
end
|
63
|
+
self.new(year, number)
|
64
|
+
end
|
65
|
+
|
66
|
+
def dump(month)
|
67
|
+
raise_dump_error(month) unless month.is_a?(self)
|
68
|
+
month.to_i
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def active_record?
|
74
|
+
Object.const_defined?("::ActiveRecord::SerializationTypeMismatch")
|
75
|
+
end
|
76
|
+
|
77
|
+
def argument_error_class
|
78
|
+
active_record? ? ::ActiveRecord::SerializationTypeMismatch : ArgumentError
|
79
|
+
end
|
80
|
+
|
81
|
+
def raise_load_error(obj)
|
82
|
+
raise argument_error_class, "Argument was supposed to be an Integer, but was a #{obj.class}. -- #{obj.inspect}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def raise_dump_error(obj)
|
86
|
+
raise argument_error_class, "Argument was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_i
|
92
|
+
yr = year
|
93
|
+
mon = number
|
94
|
+
if number == 12
|
95
|
+
mon = 0
|
96
|
+
yr += 1
|
97
|
+
end
|
98
|
+
yr * 12 + mon
|
99
|
+
end
|
100
|
+
|
101
|
+
# Does the same thing as Month#start_date, but to_<class> is a common idiom
|
102
|
+
# for built-in class conversion methods.
|
103
|
+
def to_date
|
104
|
+
Date.new(year, number, 1)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Add this to the bootstrapping process of your app, somewhere after Month is loaded.
|
109
|
+
# In Rails, config/initializers/month-serializer.rb would be perfect!
|
110
|
+
# Month.send(:include, Month::Serializer)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# NOTE: Have to use __FILE__ until Ruby 1.x support is dropped
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'month/serializer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'month-serializer'
|
8
|
+
spec.version = Month::Serializer::VERSION
|
9
|
+
spec.authors = ['Peter Boling']
|
10
|
+
spec.email = ['peter.boling@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Serialize Month objects to Integer'
|
13
|
+
spec.description = 'Serialize Month objects to Integer'
|
14
|
+
spec.homepage = 'https://github.com/pboling/month-serializer'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
spec.required_ruby_version = '>= 1.9.3'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'month', '>= 1.4.0'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'appraisal'
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
29
|
+
spec.add_development_dependency 'rake', ['>= 10.0', '<= 13']
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
31
|
+
spec.add_development_dependency 'rspec-pending_for', '~> 0.1'
|
32
|
+
spec.add_development_dependency 'rspec-block_is_expected', '~> 1.0'
|
33
|
+
spec.add_development_dependency 'wwtd'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: month-serializer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Boling
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: month
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
- - "<="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '13'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '10.0'
|
72
|
+
- - "<="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '13'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.8'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.8'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec-pending_for
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.1'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.1'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec-block_is_expected
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: wwtd
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
description: Serialize Month objects to Integer
|
132
|
+
email:
|
133
|
+
- peter.boling@gmail.com
|
134
|
+
executables: []
|
135
|
+
extensions: []
|
136
|
+
extra_rdoc_files: []
|
137
|
+
files:
|
138
|
+
- ".gitignore"
|
139
|
+
- ".rspec"
|
140
|
+
- ".rubocop.yml"
|
141
|
+
- ".travis.yml"
|
142
|
+
- Appraisals
|
143
|
+
- CODE_OF_CONDUCT.md
|
144
|
+
- Gemfile
|
145
|
+
- LICENSE
|
146
|
+
- README.md
|
147
|
+
- Rakefile
|
148
|
+
- bin/console
|
149
|
+
- bin/setup
|
150
|
+
- gemfiles/jruby_1.7.26.gemfile
|
151
|
+
- gemfiles/jruby_9.1.9.0.gemfile
|
152
|
+
- gemfiles/jruby_9.2.0.0.gemfile
|
153
|
+
- gemfiles/jruby_head.gemfile
|
154
|
+
- gemfiles/ruby_1.9.3_p551.gemfile
|
155
|
+
- gemfiles/ruby_2.0.0_p648.gemfile
|
156
|
+
- gemfiles/ruby_2.1.10.gemfile
|
157
|
+
- gemfiles/ruby_2.2.10.gemfile
|
158
|
+
- gemfiles/ruby_2.3.7.gemfile
|
159
|
+
- gemfiles/ruby_2.4.4.gemfile
|
160
|
+
- gemfiles/ruby_2.5.1.gemfile
|
161
|
+
- gemfiles/ruby_head.gemfile
|
162
|
+
- lib/month/serializer.rb
|
163
|
+
- lib/month/serializer/version.rb
|
164
|
+
- month-serializer.gemspec
|
165
|
+
homepage: https://github.com/pboling/month-serializer
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
metadata: {}
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: 1.9.3
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 2.7.7
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: Serialize Month objects to Integer
|
189
|
+
test_files: []
|