time_for_a_boolean 0.0.1

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: 2ccfb9d954ec1b87356eb15fcd7591c7e6deca75
4
+ data.tar.gz: 8c49ad2cec75e5264bed1cabf44f2754c748cc01
5
+ SHA512:
6
+ metadata.gz: 658e3d140b0e04e3000e2925254fa1402fe64098462f10a3415e2b5666cb88e12854f34b4623642afa22407a9e6c47dec850926efb6bdcaedc7eabc648b7aac4
7
+ data.tar.gz: 642f736c2fb5f85e98da4ac6ecf980e42885bad0958054e928f9ed2b700814368027e02055339c80e975befb96bf038b65f0228f0a55d0086e2183295b346084
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ time_for_a_boolean
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in time_for_a_boolean.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Caleb Thompson and thoughtbot
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,29 @@
1
+ # TimeForABoolean
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'time_for_a_boolean'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install time_for_a_boolean
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,9 @@
1
+ module TimeForABoolean
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'time_for_a_boolean' do
4
+ ActiveSupport.on_load :active_record do
5
+ extend TimeForABoolean
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TimeForABoolean
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+ require 'time_for_a_boolean/version'
3
+ require 'time_for_a_boolean/railtie'
4
+
5
+ module TimeForABoolean
6
+ def time_for_a_boolean(attribute)
7
+ define_method(attribute) { !send("#{attribute}_at").nil? }
8
+ alias_method "#{attribute}?", attribute
9
+ define_method("#{attribute}=") do |value|
10
+ if value
11
+ send("#{attribute}_at=", -> { DateTime.now }.())
12
+ else
13
+ send("#{attribute}_at=", nil)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,86 @@
1
+ require 'time_for_a_boolean'
2
+
3
+ describe TimeForABoolean do
4
+ it 'defines the attribute method' do
5
+ klass.time_for_a_boolean :attribute
6
+
7
+ expect(klass.new).to respond_to :attribute
8
+ end
9
+
10
+ it 'defines the query method' do
11
+ klass.time_for_a_boolean :attribute
12
+
13
+ expect(klass.new).to respond_to :attribute?
14
+ end
15
+
16
+ it 'defines the attribute writer' do
17
+ klass.time_for_a_boolean :attribute
18
+
19
+ expect(klass.new).to respond_to :attribute=
20
+ end
21
+
22
+ describe 'attribute method' do
23
+ it 'calls nil? on the backing timestamp' do
24
+ klass.time_for_a_boolean :attribute
25
+ timestamp = double(nil?: false)
26
+ object.stub(attribute_at: timestamp)
27
+
28
+ object.attribute
29
+
30
+ expect(timestamp).to have_received(:nil?)
31
+ end
32
+
33
+ it 'is true if the attribute is not nil' do
34
+ klass.time_for_a_boolean :attribute
35
+ object.stub(attribute_at: true)
36
+
37
+ expect(object.attribute).to be_true
38
+ end
39
+
40
+ it 'is false if the attribute is nil' do
41
+ klass.time_for_a_boolean :attribute
42
+ object.stub(attribute_at: nil)
43
+
44
+ expect(object.attribute).to be_false
45
+ end
46
+ end
47
+
48
+ describe 'the query method' do
49
+ it 'is an alias for the attribute method' do
50
+ klass.time_for_a_boolean :attribute
51
+
52
+ expect(object.method(:attribute?)).to eq object.method(:attribute)
53
+ end
54
+ end
55
+
56
+ describe 'the writer method' do
57
+ it 'sets the timestamp to now if value is true' do
58
+ klass.time_for_a_boolean :attribute
59
+ klass.send(:attr_accessor, :attribute_at)
60
+
61
+ object.attribute = true
62
+
63
+ expect(object.attribute_at).to be_kind_of(DateTime)
64
+ end
65
+
66
+ it 'sets the timestamp to nil if value is false' do
67
+ klass.time_for_a_boolean :attribute
68
+ klass.send(:attr_accessor, :attribute_at)
69
+
70
+ object.attribute_at = DateTime.now
71
+ object.attribute = false
72
+
73
+ expect(object.attribute_at).to be_nil
74
+ end
75
+ end
76
+
77
+ def klass
78
+ @klass ||= Class.new do
79
+ extend TimeForABoolean
80
+ end
81
+ end
82
+
83
+ def object
84
+ @object ||= klass.new
85
+ end
86
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'time_for_a_boolean/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'time_for_a_boolean'
8
+ spec.version = TimeForABoolean::VERSION
9
+ spec.authors = ['Caleb Thompson']
10
+ spec.email = ['caleb@calebthompson.io']
11
+ spec.description = <<-DESCRIPTION
12
+ Use timestamp values to represent boolean data such as deleted, published,
13
+ or subscribed.
14
+ DESCRIPTION
15
+ spec.summary = 'Back boolean values with timestamps'
16
+ spec.homepage = 'https://github.com/thoughtbot/time_for_a_boolean'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.test_files = spec.files.grep(%r{^spec/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'rails'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
28
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_for_a_boolean
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Caleb Thompson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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: |2
70
+ Use timestamp values to represent boolean data such as deleted, published,
71
+ or subscribed.
72
+ email:
73
+ - caleb@calebthompson.io
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .ruby-gemset
80
+ - .ruby-version
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - lib/time_for_a_boolean.rb
86
+ - lib/time_for_a_boolean/railtie.rb
87
+ - lib/time_for_a_boolean/version.rb
88
+ - spec/time_for_a_boolean_spec.rb
89
+ - time_for_a_boolean.gemspec
90
+ homepage: https://github.com/thoughtbot/time_for_a_boolean
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.5
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Back boolean values with timestamps
114
+ test_files:
115
+ - spec/time_for_a_boolean_spec.rb