boolean_timestamps 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: 9a159903694d6bf3bc9832549f984b0c587869ef
4
+ data.tar.gz: d288d095d7929b61064e20a76e71ecb46d6e2ed0
5
+ SHA512:
6
+ metadata.gz: 5358fce17d3fb3f87ab9c5545d58cab2b31d5b7486090997e002b54b3c87c3dd6642efecaa087f4621d1ad37c053d49b442363ee42dfc2416c26b5d8071fe224
7
+ data.tar.gz: 110036109b3ecdc8b02eef3cfd2861f7f65fd788be2110700355cef205341b36d05efbd7e8ef77cbdd032da6f5f24537138f57472e86ccbed2b47c012fdd05ad
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.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boolean_timestamps.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 BetterUp
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # BooleanTimestamps
2
+
3
+ > Use boolean API's on your model, and persist the boolean as a timestamp when
4
+ it was changed
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'boolean_timestamps'
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ class Post < ActiveRecord::Base
18
+ # assume published_at is in the schema
19
+ boolean_timestamps :published_at
20
+ end
21
+ ```
22
+
23
+ ## Example
24
+
25
+ ```ruby
26
+ # use the boolean attribute to auto-update the timestamp attribute
27
+ post = Post.create!(published: true)
28
+ puts post.published_at
29
+ #=> 2015-10-17 08:27
30
+
31
+ # clear the timestamp with by setting the boolean to false
32
+ post.update!(published: false)
33
+ puts post.published_at
34
+ #=> nil
35
+ ```
36
+
37
+ ## Development
38
+
39
+ 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.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/betterup/boolean_timestamps.
46
+
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 "boolean_timestamps"
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,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boolean_timestamps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "boolean_timestamps"
8
+ spec.version = BooleanTimestamps::VERSION
9
+ spec.authors = ["BetterUp Developers"]
10
+ spec.email = ["developers@betterup.co"]
11
+
12
+ spec.summary = %q{Add boolean attributes to models for simple timestamps}
13
+ spec.description = %q{Add boolean psuedo attributes to models that transparently manage underlying timestamp attributes}
14
+ spec.homepage = "https://www.github.com/betterup/boolean_timestamps"
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.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,30 @@
1
+ require 'boolean_timestamps/version'
2
+ require 'active_support/concern'
3
+
4
+ module BooleanTimestamps
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def boolean_timestamps(*attributes)
9
+ attributes.each do |timestamp_attribute|
10
+ boolean_attribute = timestamp_attribute.to_s.gsub('_at', '')
11
+ define_method boolean_attribute do
12
+ send("#{timestamp_attribute}?")
13
+ end
14
+ define_method "#{boolean_attribute}?" do
15
+ send("#{timestamp_attribute}?")
16
+ end
17
+ define_method "#{boolean_attribute}=" do |value|
18
+ boolean_value = ActiveRecord::Type::Boolean.new.type_cast_from_database(value)
19
+ unless boolean_value && send("#{timestamp_attribute}?")
20
+ timestamp = boolean_value ? Time.zone.now : nil
21
+ send("#{timestamp_attribute}=", timestamp)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ ActiveSupport.on_load(:active_record) do
29
+ include BooleanTimestamps
30
+ end
@@ -0,0 +1,3 @@
1
+ module BooleanTimestamps
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boolean_timestamps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BetterUp Developers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-17 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '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
+ description: Add boolean psuedo attributes to models that transparently manage underlying
56
+ timestamp attributes
57
+ email:
58
+ - developers@betterup.co
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - boolean_timestamps.gemspec
73
+ - lib/boolean_timestamps.rb
74
+ - lib/boolean_timestamps/version.rb
75
+ homepage: https://www.github.com/betterup/boolean_timestamps
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.8
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Add boolean attributes to models for simple timestamps
98
+ test_files: []
99
+ has_rdoc: