lifespan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d665f03a160fe60ad4e9248acd48f90f0fd1937b
4
+ data.tar.gz: eec509664fe5882e1bb2a10a765526e2961c6a6c
5
+ SHA512:
6
+ metadata.gz: de446452c6bc54dc55e25e89719d504e0856df8d7a8c9d689ac20da6cefc0c85f351def290421231818948106935d27f176d0096244e24c3f2f226ea1ff965b5
7
+ data.tar.gz: 47bc4cc13b6eb7505f7f207ed0d6972979bd4a1741c897790b41c7f4043e66175e96e3a2e602de3a57484a51da3de35d4ef18da4b164f85c6416a5db7847df37
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+
3
+ #cache: bundler
4
+
5
+ before_install:
6
+ - env
7
+ # - gem update --system
8
+ # - gem update bundler
9
+
10
+ before_script:
11
+ - bundle exec rake lifespan:db:create
12
+
13
+ rvm:
14
+ - 2.2
15
+ - ruby-head
16
+
17
+ gemfile:
18
+ - gemfiles/rails4_0.gemfile
19
+ - gemfiles/rails4_1.gemfile
20
+ - gemfiles/rails4_2.gemfile
21
+
22
+ matrix:
23
+ allow_failures:
24
+ - rvm: ruby-head
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lifespan.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Gen Takahashi
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.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Lifespan
2
+
3
+ [![Build Status](https://travis-ci.org/gendosu/lifespan.svg?branch=master)](https://travis-ci.org/gendosu/lifespan)
4
+
5
+ This +lifespan+ extension provides filtering of record at the start_at and end_at.<br/>
6
+ Automatically adding to default_scope.<br/>
7
+ without_lifespan method a good job.<br/>
8
+ It is not erased only default_scope itself has added.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ TODO: It is scheduled to be able to support rubygem install
15
+
16
+ ```ruby
17
+ gem 'lifespan'
18
+ ```
19
+ or
20
+ ```ruby
21
+ gem 'lifespan', github: 'gendosu/lifespan'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install lifespan
31
+
32
+ ## Usage
33
+
34
+ ```Ruby
35
+ class Article < ActiveRecord::Base
36
+ lifespan start_at_column: "start_on"
37
+ end
38
+ ```
39
+
40
+ How to use:
41
+
42
+ ```shell
43
+ Article.all
44
+ => SELECT
45
+ `articles`.*
46
+ FROM
47
+ `articles`
48
+ WHERE
49
+ (`articles`.`start_at` <= '2115-03-31 15:00:00.000072') AND
50
+ (`articles`.`end_at` > '2115-03-31 15:00:00.000072' OR `articles`.`end_at` IS NULL);
51
+ ```
52
+
53
+ ## Development
54
+
55
+ TODO
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+
7
+ require 'active_record'
8
+ require 'mysql2'
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = FileList['spec/**/*_spec.rb']
12
+ end
13
+
14
+ namespace :lifespan do
15
+ namespace :db do
16
+ task :rails_env do
17
+ unless defined? RAILS_ENV
18
+ RAILS_ENV = ENV['RAILS_ENV'] ||= 'test'
19
+ end
20
+ end
21
+
22
+ task :load_config => :rails_env do
23
+ yaml_file = File.join(File.dirname(__FILE__), 'spec/config/database.yml')
24
+ ActiveRecord::Base.configurations = YAML.load ERB.new(IO.read(yaml_file)).result
25
+ end
26
+
27
+ desc "create test database"
28
+ task :create => :load_config do
29
+ ActiveRecord::Tasks::DatabaseTasks.create_current(RAILS_ENV)
30
+ end
31
+
32
+ desc "drop test database"
33
+ task :drop => :load_config do
34
+ ActiveRecord::Tasks::DatabaseTasks.drop_current(RAILS_ENV)
35
+ end
36
+ end
37
+ end
38
+
39
+ namespace :test do
40
+ desc 'for travis ci'
41
+ task :travis do
42
+ ["rake spec"].each do |cmd|
43
+ puts "Starting to run #{cmd}..."
44
+ system("export DISPLAY=:99.0 && bundle exec #{cmd}")
45
+ raise "#{cmd} failed!" unless $?.exitstatus == 0
46
+ end
47
+ end
48
+ end
49
+
50
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lifespan"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', "~> 4.0.0"
4
+ gem 'activesupport', "~> 4.0.0"
5
+
6
+ gemspec :path => '../'
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', "~> 4.1.0"
4
+ gem 'activesupport', "~> 4.1.0"
5
+
6
+ gemspec :path => '../'
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', "~> 4.2.0"
4
+ gem 'activesupport', "~> 4.2.0"
5
+
6
+ gemspec :path => '../'
data/lib/lifespan.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'active_record' unless defined? ActiveRecord
2
+ require 'active_support' unless defined? ActiveSupport
3
+
4
+ module Lifespan
5
+
6
+ def self.included(klazz)
7
+ klazz.extend Query
8
+ end
9
+
10
+ module Query
11
+ def without_lifespan
12
+ self.default_scopes.each do |scope|
13
+ self.default_scopes.delete(scope) if scope.source_location[0].eql?(__FILE__)
14
+ end
15
+ all
16
+ end
17
+ end
18
+ end
19
+
20
+ class ActiveRecord::Base
21
+ ##
22
+ # This +lifespan+ extension provides filtering of record at the start_at and end_at.
23
+ # Automatically adding to default_scope.
24
+ # without_lifespan method a good job.
25
+ # It is not erased only default_scope itself has added.
26
+ #
27
+ # Configuration options are:
28
+ #
29
+ # * +start_at_column+ - column name for start datetime columne, default +start_at+
30
+ # * +end_at_column+ - column name for end datetime columne, default +end_at+
31
+ #
32
+ # Example Option:
33
+ #
34
+ # class Article < ActiveRecord::Base
35
+ # lifespan start_at_column: "start_on"
36
+ # end
37
+ #
38
+ # How to use:
39
+ #
40
+ # Article.all
41
+ # => SELECT
42
+ # `articles`.*
43
+ # FROM
44
+ # `articles`
45
+ # WHERE
46
+ # (`articles`.`start_at` <= '2115-03-31 15:00:00.000072') AND
47
+ # (`articles`.`end_at` > '2115-03-31 15:00:00.000072' OR `articles`.`end_at` IS NULL);
48
+ #
49
+ def self.lifespan(options={})
50
+ include Lifespan
51
+
52
+ class_attribute :start_at_column, :end_at_column
53
+
54
+ self.start_at_column = (options[:start_at_column] || :start_at).to_s
55
+ self.end_at_column = (options[:end_at_column] || :end_at).to_s
56
+
57
+ def self.lifespan_scope
58
+ #TODO Time.zone.nowの方が良い?
59
+ now = Time.now
60
+ where(arel_table[start_at_column].lteq now)
61
+ .where(arel_table[end_at_column].gt(now).or arel_table[end_at_column].eq(nil))
62
+ end
63
+ default_scope { lifespan_scope }
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module Lifespan
2
+ VERSION = "0.1.0"
3
+ end
data/lifespan.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lifespan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lifespan"
8
+ spec.version = Lifespan::VERSION
9
+ spec.authors = ["Gen Takahashi"]
10
+ spec.email = ["gendosu@gmail.com"]
11
+
12
+ spec.summary = "provides filtering of data at the start_at and end_at"
13
+ spec.description = "provides filtering of data at the start_at and end_at"
14
+ spec.homepage = "https://github.com/gendosu/lifespan"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ unless ENV['TRAVIS']
22
+ spec.add_runtime_dependency "activerecord", ">= 4.0.0", "< 5.0"
23
+ spec.add_runtime_dependency "activesuport", ">= 4.0.0", "< 5.0"
24
+ end
25
+
26
+ spec.add_development_dependency "bundler"#, "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+
29
+ spec.add_development_dependency "rspec", "~> 3.1.0"
30
+ spec.add_development_dependency "mysql2"
31
+ spec.add_development_dependency "factory_girl", "~> 4.4.0"
32
+ spec.add_development_dependency "delorean"
33
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lifespan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gen Takahashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesuport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 4.0.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 4.0.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 3.1.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 3.1.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: mysql2
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: factory_girl
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 4.4.0
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 4.4.0
123
+ - !ruby/object:Gem::Dependency
124
+ name: delorean
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ description: provides filtering of data at the start_at and end_at
138
+ email:
139
+ - gendosu@gmail.com
140
+ executables: []
141
+ extensions: []
142
+ extra_rdoc_files: []
143
+ files:
144
+ - ".gitignore"
145
+ - ".travis.yml"
146
+ - CODE_OF_CONDUCT.md
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - bin/console
152
+ - bin/setup
153
+ - gemfiles/rails4_0.gemfile
154
+ - gemfiles/rails4_1.gemfile
155
+ - gemfiles/rails4_2.gemfile
156
+ - lib/lifespan.rb
157
+ - lib/lifespan/version.rb
158
+ - lifespan.gemspec
159
+ homepage: https://github.com/gendosu/lifespan
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.5
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: provides filtering of data at the start_at and end_at
183
+ test_files: []