groundhog_day 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db15bf1f906f65b382225eac929d5f62e683cf54
4
+ data.tar.gz: 8368dd553acfb33b99c3743a4427fc3e82fb5da4
5
+ SHA512:
6
+ metadata.gz: 1020e69076d6d1b1f58500c91e0f12d9541df04a31bf13bca61c5003f465fa4822c13fe62728dbce9f30ee361a3d9e330617f130e04aaf8599eeb311ef7f4a03
7
+ data.tar.gz: 5f64a858b3adf49db99943e80f41e7e9083e6e0f40eb83cb9713a3ba4633c548dbc6f77615bf7a8b9df85438156b5774858a04ea891cd6bb6637c65ae87e9c00
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in groundhog_day.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Zach Taylor
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,82 @@
1
+ # GroundhogDay
2
+
3
+ Monkey patches Date, Time, and DateTime to replay a day over, and over, and over. Original use case: Fork a production database, run a long task on a certain day. Make some changes, run the same long task on the same day.
4
+
5
+ ![Groundhog Day](http://www.lionsroar.com/wp-content/uploads/2009/05/groundhog-day-driving.jpg)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'groundhog_day'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install groundhog_day
22
+
23
+ ## Usage
24
+ #### Repeating Date:
25
+ Today will always be the date provided.
26
+ ```ruby
27
+ Date.today # => 2016-02-02
28
+
29
+ GroundhogDay.enable! date: Date.new(2014, 11, 15)
30
+
31
+ Date.today # => 2014-11-15
32
+
33
+ # ... wait for a day to pass
34
+ Date.today # => 2014-11-15
35
+
36
+ GroundhogDay.disable!
37
+
38
+ Date.today # => 2016-02-03
39
+ ```
40
+ #### Repeating Time:
41
+ Now will always be the date provided, but time will be real-time.
42
+
43
+ ```ruby
44
+ Time.now # => 2016-02-02 10:00:00 -0600
45
+
46
+ GroundhogDay.enable! date: Date.new(2014, 11, 15)
47
+
48
+ Time.now # => 2014-11-15 10:00:05 -0600
49
+
50
+ # ... wait 10 minutes
51
+ Time.now # => 2014-11-15 10:10:05 -0600
52
+
53
+ GroundhogDay.disable!
54
+
55
+ Time.now # => 2016-01-29 10:10:10 -0600
56
+ ```
57
+
58
+ #### Rails
59
+ ```ruby
60
+ # config/initializers/groundhog_day.rb
61
+
62
+ if (groundhog_date = ENV['GROUNDHOG_DATE'])
63
+ require 'groundhog_day'
64
+ GroundhogDay.enable! date: Date.parse(groundhog_date)
65
+ end
66
+ ```
67
+
68
+ ## Development
69
+
70
+ 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.
71
+
72
+ 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).
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/taylorzr/groundhog_day.
77
+
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "groundhog_day"
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,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,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'groundhog_day/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "groundhog_day"
8
+ spec.version = GroundhogDay::VERSION
9
+ spec.authors = ["Zach Taylor"]
10
+ spec.email = ["taylorzr@gmail.com"]
11
+
12
+ spec.summary = %q{Monkey patch Date & Time to replay the same day over, and over, and over...}
13
+ spec.homepage = "https://github.com/taylorzr/groundhog_day"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "pry"
25
+ end
@@ -0,0 +1,44 @@
1
+ require 'groundhog_day/version'
2
+ require 'groundhog_day/date_extensions'
3
+ require 'groundhog_day/time_extensions'
4
+ require 'groundhog_day/datetime_extensions'
5
+ require 'date'
6
+
7
+ module GroundhogDay
8
+ class << self
9
+ def enable!(date: Date.new(1982, 6, 16))
10
+ @date = parse_date date
11
+ Time.singleton_class.prepend TimeExtensions unless Time.singleton_class.ancestors.include? TimeExtensions
12
+ Date.singleton_class.prepend DateExtensions unless Date.singleton_class.ancestors.include? DateExtensions
13
+ DateTime.singleton_class.prepend DateTimeExtensions unless DateTime.singleton_class.ancestors.include? DateTimeExtensions
14
+ @enabled = true
15
+ end
16
+
17
+ def disable!
18
+ @enabled = false
19
+ end
20
+
21
+ def enabled?
22
+ @enabled
23
+ end
24
+
25
+ def date
26
+ @date
27
+ end
28
+
29
+ def date=(value)
30
+ @date = value.to_date
31
+ end
32
+
33
+ private
34
+
35
+ def parse_date(date)
36
+ if date.is_a? String
37
+ Date.parse date
38
+ else
39
+ date.to_date
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,11 @@
1
+ module GroundhogDay
2
+ module DateExtensions
3
+ def today
4
+ if GroundhogDay.enabled?
5
+ GroundhogDay.date
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module GroundhogDay
2
+ module DateTimeExtensions
3
+ def now
4
+ if GroundhogDay.enabled?
5
+ actual_now = super
6
+ DateTime.new GroundhogDay.date.year, GroundhogDay.date.month, GroundhogDay.date.day, actual_now.hour, actual_now.min, actual_now.sec, actual_now.offset, actual_now.sec_fraction
7
+ else
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module GroundhogDay
2
+ module TimeExtensions
3
+ def now
4
+ if GroundhogDay.enabled?
5
+ actual_now = super
6
+ Time.new GroundhogDay.date.year, GroundhogDay.date.month, GroundhogDay.date.day, actual_now.hour, actual_now.min, actual_now.sec, actual_now.utc_offset
7
+ else
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module GroundhogDay
2
+ VERSION = "0.1.0"
3
+ end
data/tags ADDED
Binary file
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: groundhog_day
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zach Taylor
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - taylorzr@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - groundhog_day.gemspec
86
+ - lib/groundhog_day.rb
87
+ - lib/groundhog_day/date_extensions.rb
88
+ - lib/groundhog_day/datetime_extensions.rb
89
+ - lib/groundhog_day/time_extensions.rb
90
+ - lib/groundhog_day/version.rb
91
+ - tags
92
+ homepage: https://github.com/taylorzr/groundhog_day
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Monkey patch Date & Time to replay the same day over, and over, and over...
116
+ test_files: []
117
+ has_rdoc: