time_for_a_boolean 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ccfb9d954ec1b87356eb15fcd7591c7e6deca75
4
- data.tar.gz: 8c49ad2cec75e5264bed1cabf44f2754c748cc01
3
+ metadata.gz: b911b8e5eb898861b4bd685d9cca9077c24d2ac3
4
+ data.tar.gz: 4b608bfe50aad84b8db5de8420acb6652eb2dd56
5
5
  SHA512:
6
- metadata.gz: 658e3d140b0e04e3000e2925254fa1402fe64098462f10a3415e2b5666cb88e12854f34b4623642afa22407a9e6c47dec850926efb6bdcaedc7eabc648b7aac4
7
- data.tar.gz: 642f736c2fb5f85e98da4ac6ecf980e42885bad0958054e928f9ed2b700814368027e02055339c80e975befb96bf038b65f0228f0a55d0086e2183295b346084
6
+ metadata.gz: 3de77ccb1b78cf796faee950ef48f9593e7890480ba6407a0332ac6e13e5e64c48426f7be82f47fa6c2e7bf9828081e420f01300464a5098e0e5a4b82eefbc62
7
+ data.tar.gz: 28e4d3a903284312c50a1f4c69c474b39eb6114ae1f905a96d74ccbb580f73aa2f70f9468e46d894161c074a4caac29725ccec1af5bc809aaa0129e4d0f9f416
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.0.0-p247
1
+ 2.1.2
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,39 @@
1
+ # Contributing
2
+
3
+ I love pull requests. Here's a quick guide:
4
+
5
+ 1. Fork the repo.
6
+ 2. Run the tests. I only take pull requests with passing tests, and it's great
7
+ to know that you have a clean slate: `bundle && rake`
8
+ 3. Add a test for your change. Only refactoring and documentation changes
9
+ require no new tests. If you are adding functionality or fixing a bug, I need
10
+ a test!
11
+ 4. Make the test pass.
12
+ 5. Make sure your changes adhere to the
13
+ [thoughtbot Style Guide](https://github.com/thoughtbot/guides/tree/master/style)
14
+ 6. Write an [awesome] [commit] [message].
15
+ [awesome]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
16
+ [commit]: http://robots.thoughtbot.com/post/48933156625/5-useful-tips-for-a-better-commit-message
17
+ [message]: http://rakeroutes.com/blog/deliberate-git/
18
+ 6. Push to your fork and submit a pull request.
19
+ 7. At this point you're waiting on us. I like to at least comment on, if not
20
+ accept, pull requests within a few days (and, typically, one business
21
+ day). I may suggest some changes or improvements or alternatives.
22
+
23
+ ## Increase your chances of getting merged
24
+
25
+ Some things that will increase the chance that your pull request is accepted,
26
+ taken straight from the Ruby on Rails guide:
27
+
28
+ 1. Use Rails idioms and helpers
29
+ 2. Include tests that fail without your code, and pass with it
30
+ 3. Update the documentation, the surrounding one, examples elsewhere, guides,
31
+ whatever is affected by your contribution
32
+ 4. Syntax:
33
+ * Two spaces, no tabs.
34
+ * No trailing whitespace. Blank lines should not have any space.
35
+ * Prefer `&&`/`||` over `and`/`or`.
36
+ * `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
37
+ * `a = b` and not `a=b`.
38
+ * Follow the conventions you see used in the source already.
39
+ 5. And in case I didn't emphasize it enough: I love tests!
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Caleb Thompson and thoughtbot
1
+ Copyright (c) 2013 Caleb Thompson
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,29 +1,79 @@
1
- # TimeForABoolean
1
+ Time for A Boolean
2
+ ==================
2
3
 
3
- TODO: Write a gem description
4
+ [![Build Status](https://travis-ci.org/calebthompson/time_for_a_boolean.png)](https://travis-ci.org/calebthompson/time_for_a_boolean)
5
+ [![Code Climate](https://codeclimate.com/github/calebthompson/time_for_a_boolean.png)](https://codeclimate.com/github/calebthompson/time_for_a_boolean)
6
+ [![Coverage Status](https://coveralls.io/repos/calebthompson/time_for_a_boolean/badge.png)](https://coveralls.io/r/calebthompson/time_for_a_boolean)
4
7
 
5
- ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ > Sally: Hey, we need to add a flag to Post
8
10
 
9
- gem 'time_for_a_boolean'
11
+ > Jean: What for?
10
12
 
11
- And then execute:
13
+ > Sally: Well, we want to let users "delete" posts, but not actually lose the
14
+ data.
12
15
 
13
- $ bundle
16
+ > Jean: Sounds reasonable. But what about later, when we have to know _when_ a
17
+ post was deleted?
14
18
 
15
- Or install it yourself as:
19
+ > Sally: That's a good point, but if we add a timestamp now we have to write all
20
+ sorts of methods to keep a nice interface on Post...
16
21
 
17
- $ gem install time_for_a_boolean
22
+ > Jean: Time for A Boolean!
18
23
 
19
- ## Usage
24
+ Wait, what?
25
+ -----------
20
26
 
21
- TODO: Write usage instructions here
27
+ ```
28
+ rails generate migration AddDeletedAtToPosts deleted_at:timestamp
29
+ ```
22
30
 
23
- ## Contributing
31
+ ```ruby
32
+ class Post < ActiveRecord::Base
33
+ time_for_a_boolean :deleted
34
+ ...
35
+ end
36
+ ```
24
37
 
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
38
+ ```ruby
39
+ class PostsController < ApplicationController
40
+ def show
41
+ @post = Post.find(params[:id])
42
+ if @post.deleted?
43
+ raise ActiveRecord::RecordNotFound
44
+ end
45
+ end
46
+
47
+ def destroy
48
+ post = Post.find(params[:id])
49
+ post.deleted = true
50
+ post.save
51
+ redirect_to posts_url
52
+ end
53
+ end
54
+ ```
55
+
56
+ You keep on saying things and I don't get it.
57
+ ---------------------------------------------
58
+
59
+ Okay, let's take a look at what happens.
60
+
61
+ When we call `time_for_a_boolean :deleted` in the Post class definition, several
62
+ methods are defined:
63
+
64
+ | Method | Description
65
+ | --------------- | -----------
66
+ | `Post#deleted` | `true` if `Post#deleted_at` is set, `false` otherwise
67
+ | `Post#deleted?` | Alias for `Post#deleted`
68
+ | `Post#deleted=` | Sets the timestamp to `DateTime.now` if the new value is true, and `nil` otherwise
69
+
70
+ These methods allow you to use a timestamp as you would a boolean value in your
71
+ application.
72
+
73
+ Okay... why?
74
+ ------------
75
+
76
+ * Audit for when a flag was set. Future you wants this.
77
+ * `COUNT(posts.deleted_at)` gives you the count of deleted posts, which is
78
+ useful when writing a report. Define and use `Post.deleted.count` when you
79
+ have Ruby available.
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -1,3 +1,3 @@
1
1
  module TimeForABoolean
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -4,7 +4,10 @@ require 'time_for_a_boolean/railtie'
4
4
 
5
5
  module TimeForABoolean
6
6
  def time_for_a_boolean(attribute)
7
- define_method(attribute) { !send("#{attribute}_at").nil? }
7
+ define_method(attribute) do
8
+ !send("#{attribute}_at").nil? &&
9
+ send("#{attribute}_at") <= -> { DateTime.now }.()
10
+ end
8
11
  alias_method "#{attribute}?", attribute
9
12
  define_method("#{attribute}=") do |value|
10
13
  if value
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'time_for_a_boolean'
2
5
 
3
6
  describe TimeForABoolean do
@@ -22,7 +25,7 @@ describe TimeForABoolean do
22
25
  describe 'attribute method' do
23
26
  it 'calls nil? on the backing timestamp' do
24
27
  klass.time_for_a_boolean :attribute
25
- timestamp = double(nil?: false)
28
+ timestamp = double(nil?: true)
26
29
  object.stub(attribute_at: timestamp)
27
30
 
28
31
  object.attribute
@@ -32,7 +35,7 @@ describe TimeForABoolean do
32
35
 
33
36
  it 'is true if the attribute is not nil' do
34
37
  klass.time_for_a_boolean :attribute
35
- object.stub(attribute_at: true)
38
+ object.stub(attribute_at: DateTime.now - 10)
36
39
 
37
40
  expect(object.attribute).to be_true
38
41
  end
@@ -43,6 +46,13 @@ describe TimeForABoolean do
43
46
 
44
47
  expect(object.attribute).to be_false
45
48
  end
49
+
50
+ it 'is false if the attribute time is in the future' do
51
+ klass.time_for_a_boolean :attribute
52
+ object.stub(attribute_at: Time.now + 86400) # one day in the future
53
+
54
+ expect(object.attribute).to be_false
55
+ end
46
56
  end
47
57
 
48
58
  describe 'the query method' do
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  or subscribed.
14
14
  DESCRIPTION
15
15
  spec.summary = 'Back boolean values with timestamps'
16
- spec.homepage = 'https://github.com/thoughtbot/time_for_a_boolean'
16
+ spec.homepage = 'https://github.com/calebthompson/time_for_a_boolean'
17
17
  spec.license = 'MIT'
18
18
 
19
19
  spec.files = `git ls-files`.split($/)
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'rails'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'coveralls'
26
27
  spec.add_development_dependency 'rake'
27
28
  spec.add_development_dependency 'rspec'
28
29
  end
metadata CHANGED
@@ -1,69 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_for_a_boolean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-31 00:00:00.000000000 Z
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
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'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '>='
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  description: |2
@@ -75,9 +89,10 @@ executables: []
75
89
  extensions: []
76
90
  extra_rdoc_files: []
77
91
  files:
78
- - .gitignore
79
- - .ruby-gemset
80
- - .ruby-version
92
+ - ".gitignore"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - CONTRIBUTING.md
81
96
  - Gemfile
82
97
  - LICENSE
83
98
  - README.md
@@ -87,7 +102,7 @@ files:
87
102
  - lib/time_for_a_boolean/version.rb
88
103
  - spec/time_for_a_boolean_spec.rb
89
104
  - time_for_a_boolean.gemspec
90
- homepage: https://github.com/thoughtbot/time_for_a_boolean
105
+ homepage: https://github.com/calebthompson/time_for_a_boolean
91
106
  licenses:
92
107
  - MIT
93
108
  metadata: {}
@@ -97,17 +112,17 @@ require_paths:
97
112
  - lib
98
113
  required_ruby_version: !ruby/object:Gem::Requirement
99
114
  requirements:
100
- - - '>='
115
+ - - ">="
101
116
  - !ruby/object:Gem::Version
102
117
  version: '0'
103
118
  required_rubygems_version: !ruby/object:Gem::Requirement
104
119
  requirements:
105
- - - '>='
120
+ - - ">="
106
121
  - !ruby/object:Gem::Version
107
122
  version: '0'
108
123
  requirements: []
109
124
  rubyforge_project:
110
- rubygems_version: 2.0.5
125
+ rubygems_version: 2.2.2
111
126
  signing_key:
112
127
  specification_version: 4
113
128
  summary: Back boolean values with timestamps