month_constrain 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2dd75abb41153f0188048a7d9c4719732079aef
4
+ data.tar.gz: ce1142305ce5ad92316c0c28ce11bd1bf4fd6098
5
+ SHA512:
6
+ metadata.gz: fa52c22e9ac561892ac386c2b9d8b156a4ff184508a6f605c1189850027fcd2851e2c6d62a3485e79b760cfdbc4ef9493ce3899af16b1d6d2c24b5cac257820b
7
+ data.tar.gz: 456ddd6b1ca8ebc720e44d5de42747b1286cddd07d04543571b378c936a4ed200a58a1ad056b0c07162b01be26a73011b0a7585d301580fbffc71ad2a5d4a1f0
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,61 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - bin/**
6
+ DisplayCopNames: true
7
+
8
+ Lint/AssignmentInCondition:
9
+ Enabled: false
10
+
11
+ Metrics/AbcSize:
12
+ Max: 30
13
+
14
+ Metrics/LineLength:
15
+ Max: 128
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: false
19
+
20
+ Rails/HasAndBelongsToMany:
21
+ Enabled: false
22
+
23
+ Style/AlignParameters:
24
+ Enabled: false
25
+
26
+ Style/AsciiComments:
27
+ Enabled: false
28
+
29
+ Style/BlockComments:
30
+ Enabled: false
31
+
32
+ Style/ClassAndModuleChildren:
33
+ Enabled: false
34
+
35
+ Style/Documentation:
36
+ Enabled: false
37
+
38
+ Style/GuardClause:
39
+ Enabled: false
40
+
41
+ Style/NumericLiterals:
42
+ MinDigits: 10
43
+
44
+ Style/PercentLiteralDelimiters:
45
+ PreferredDelimiters:
46
+ '%': '{}'
47
+
48
+ Style/RedundantSelf:
49
+ Enabled: false
50
+
51
+ Style/SignalException:
52
+ Enabled: false
53
+
54
+ Style/SpaceBeforeFirstArg:
55
+ Enabled: false
56
+
57
+ Style/TrailingCommaInArguments:
58
+ EnforcedStyleForMultiline: comma
59
+
60
+ Style/TrailingCommaInLiteral:
61
+ EnforcedStyleForMultiline: comma
File without changes
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ rvm:
5
+ - 2.3.1
6
+ - 2.2.5
7
+
8
+ env:
9
+ - RAILS_VERSION=5.0.0.1
10
+ - RAILS_VERSION=4.2.7.1
11
+
12
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,2 @@
1
+ ## v1.0.0 - 2016/12/09
2
+ - First release :tada:
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at hata.yusaku.1225@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in month_constrain.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'activerecord', ENV['RAILS_VERSION'] || '5.0.0.1'
8
+ gem 'activesupport', ENV['RAILS_VERSION'] || '5.0.0.1'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © Yusaku Hatanaka (hatappi) and Speee, Inc.
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.
@@ -0,0 +1,80 @@
1
+ # MonthConstrain
2
+
3
+ month_constrain is for managing columns of Date type as month information in ActiveRecord.
4
+ Converts date information such as `Date.new(2016, 12, 12)` and `"2016-01"` to Date Class.
5
+
6
+ Supports Rails 4.x and 5.x releases.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'month_constrain'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install month_constrain
23
+
24
+ ## Usage
25
+
26
+ **In your model**
27
+
28
+ ```rb
29
+ class Book < ApplicationRecord
30
+ acts_as_month_constrain :published_on
31
+
32
+ # ...
33
+ end
34
+ ```
35
+
36
+ Create Record
37
+
38
+ e.g.
39
+
40
+ ```rb
41
+ >> Client.create(published_on: '2016-01')
42
+ # => #<Client id: 1, published_on: "2016-01-01">
43
+
44
+ >> Client.create(published_on: Date.new(2016, 1, 16))
45
+ # => #<Client id: 1, published_on: "2016-01-01">
46
+
47
+ ```
48
+
49
+ Find Record
50
+
51
+ e.g.
52
+
53
+ ```rb
54
+ >> Client.published_on('2016-01')
55
+ # => #<ActiveRecord::Relation [#<Client id: 1, published_on: "2016-01-01">]>
56
+
57
+ >> Client.published_on(Date.new(2016, 1, 16))
58
+ # => #<ActiveRecord::Relation [#<Client id: 1, published_on: "2016-01-01">]>
59
+
60
+ >> Client.published_on_in(Date.new(2016, 1, 16), nil)
61
+ # => #<ActiveRecord::Relation [#<Client id: 5, published_on: "2016-01-01">, #<Client id: 6, published_on: "2016-02-01">, #<Client id: 7, published_on: "2016-03-01">]>
62
+
63
+ >> Client.published_on_in('2016-01', '2016-02')
64
+ # => #<ActiveRecord::Relation [#<Client id: 5, published_on: "2016-01-01">, #<Client id: 6, published_on: "2016-02-01">]>
65
+
66
+ ```
67
+
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it ( https://github.com/speee/month_constrain/fork )
72
+ 2. Create your feature branch (git checkout -b my-new-feature)
73
+ 3. Commit your changes (git commit -am 'Add some feature')
74
+ 4. Push to the branch (git push origin my-new-feature)
75
+ 5. Create a new Pull Request
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: %i(rubocop spec)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "month_constrain"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require 'active_record' unless defined? ActiveRecord
2
+ require 'month_constrain/version'
3
+ require 'month_constrain/active_record_base'
4
+
5
+ ActiveRecord::Base.send :extend, MonthConstrain::ActiveRecordBase
@@ -0,0 +1,21 @@
1
+ require 'month_constrain/active_record_base/initializer'
2
+
3
+ module MonthConstrain
4
+ module ActiveRecordBase
5
+ def acts_as_month_constrain(*columns)
6
+ Initializer.setter(self, columns)
7
+ Initializer.scope(self, columns)
8
+ end
9
+
10
+ def month_constrain(value)
11
+ case value
12
+ when Date, Time, ActiveSupport::TimeWithZone
13
+ Date.new(value.year, value.month, 1)
14
+ when /\A(\d{4})-(\d{1,2})/
15
+ Date.new(Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, 1)
16
+ end
17
+ rescue ArgumentError
18
+ nil
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ module MonthConstrain::ActiveRecordBase
2
+ module Initializer
3
+ def self.setter(target_class, columns)
4
+ target_class.class_eval do
5
+ columns.each do |column|
6
+ define_method "#{column}=" do |val|
7
+ super(self.class.month_constrain(val))
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ def self.scope(target_class, columns)
14
+ target_class.class_eval do
15
+ columns.each do |column|
16
+ scope "#{column}_in".to_sym, lambda { |from, to|
17
+ relation = self
18
+ relation = relation.where(self.arel_table[column.to_sym].gteq(month_constrain(from))) if from
19
+ relation = relation.where(self.arel_table[column.to_sym].lteq(month_constrain(to))) if to
20
+ relation
21
+ }
22
+
23
+ scope column.to_s.to_sym, lambda { |val|
24
+ where(column => month_constrain(val))
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module MonthConstrain
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'month_constrain/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'month_constrain'
8
+ spec.version = MonthConstrain::VERSION
9
+ spec.authors = ['Yusaku Hatanaka (hatappi)', 'Speee, Inc.']
10
+ spec.email = ['yusaku.hatanaka@speee.jp']
11
+
12
+ spec.summary = 'month_constrain is a re-implementation of acts_as_month_constrain for Rails 4, and 5.'
13
+ spec.description = 'month_constrain is a re-implementation of acts_as_month_constrain for Rails 4, and 5.'
14
+ spec.homepage = 'https://github.com/speee/month-constrain'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'activesupport', '>= 4.2.3'
23
+ spec.add_dependency 'activerecord', '>= 4.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.12'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.43'
29
+ spec.add_development_dependency 'sqlite3', '~> 1.0'
30
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: month_constrain
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusaku Hatanaka (hatappi)
8
+ - Speee, Inc.
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 4.2.3
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 4.2.3
28
+ - !ruby/object:Gem::Dependency
29
+ name: activerecord
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '4.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '4.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.12'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.12'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.43'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.43'
98
+ - !ruby/object:Gem::Dependency
99
+ name: sqlite3
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.0'
112
+ description: month_constrain is a re-implementation of acts_as_month_constrain for
113
+ Rails 4, and 5.
114
+ email:
115
+ - yusaku.hatanaka@speee.jp
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".rubocop_todo.yml"
124
+ - ".travis.yml"
125
+ - CHANGELOG.md
126
+ - CODE_OF_CONDUCT.md
127
+ - Gemfile
128
+ - LICENSE
129
+ - README.md
130
+ - Rakefile
131
+ - bin/console
132
+ - bin/setup
133
+ - lib/month_constrain.rb
134
+ - lib/month_constrain/active_record_base.rb
135
+ - lib/month_constrain/active_record_base/initializer.rb
136
+ - lib/month_constrain/version.rb
137
+ - month_constrain.gemspec
138
+ homepage: https://github.com/speee/month-constrain
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.5.1
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: month_constrain is a re-implementation of acts_as_month_constrain for Rails
162
+ 4, and 5.
163
+ test_files: []