can_has_support 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.
- data/HISTORY +4 -0
- data/LICENSE +25 -0
- data/README +1 -0
- data/Rakefile +75 -0
- data/lib/can_has_support.rb +6 -0
- data/lib/can_has_support/fixnum_time_ext.rb +18 -0
- data/lib/can_has_support/hash_core_ext.rb +27 -0
- data/lib/can_has_support/range_time_ext.rb +32 -0
- data/lib/can_has_support/time_core_ext.rb +18 -0
- data/lib/can_has_support/version.rb +7 -0
- metadata +63 -0
data/HISTORY
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2008 Brian Smith <wbsmith83@gmail.com>
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of this project nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
17
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
20
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
21
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
22
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
23
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
24
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
README
|
data/Rakefile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "rake"
|
4
|
+
require "rake/clean"
|
5
|
+
require "rake/gempackagetask"
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
require "spec"
|
8
|
+
require "spec/rake/spectask"
|
9
|
+
|
10
|
+
DIR = File.dirname(__FILE__)
|
11
|
+
NAME = 'can_has_support'
|
12
|
+
SUMMARY =<<-EOS
|
13
|
+
EOS
|
14
|
+
|
15
|
+
require "lib/#{NAME}/version"
|
16
|
+
|
17
|
+
spec = Gem::Specification.new do |s|
|
18
|
+
s.name = NAME
|
19
|
+
s.summary = SUMMARY
|
20
|
+
|
21
|
+
s.version = CanHasSupport::VERSION
|
22
|
+
s.platform = Gem::Platform::RUBY
|
23
|
+
|
24
|
+
s.require_path = "lib"
|
25
|
+
s.files = %w(Rakefile LICENSE HISTORY README) + Dir["lib/**/*"]
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(spec) do |package|
|
29
|
+
package.gem_spec = spec
|
30
|
+
package.need_zip = true
|
31
|
+
package.need_tar = true
|
32
|
+
end
|
33
|
+
|
34
|
+
##############################################################################
|
35
|
+
# Documentation
|
36
|
+
##############################################################################
|
37
|
+
task :doc => "doc:rerdoc"
|
38
|
+
namespace :doc do
|
39
|
+
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
files = ['README', 'LICENSE', 'HISTORY',
|
42
|
+
'lib/**/*.rb', 'doc/**/*.rdoc', 'spec/**/*.rb']
|
43
|
+
rdoc.rdoc_files.add(files)
|
44
|
+
rdoc.main = 'README'
|
45
|
+
rdoc.title = 'I CAN HAS "CAN HAS FIXTURES?" DOCS? '
|
46
|
+
rdoc.template = 'tools/allison-2.0.3/lib/allison'
|
47
|
+
rdoc.rdoc_dir = "doc/#{NAME}/rdoc"
|
48
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "rdoc to rubyforge"
|
52
|
+
task :rubyforge => :doc do
|
53
|
+
sh %{chmod -R 755 doc}
|
54
|
+
sh %{/usr/bin/scp -r -p doc/#{NAME}/rdoc/* brianthecoder@rubyforge.org:/var/www/gforge-projects/canhasgems/#{NAME}}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
##############################################################################
|
59
|
+
# rSpec & rcov
|
60
|
+
##############################################################################
|
61
|
+
desc "Run all specs"
|
62
|
+
Spec::Rake::SpecTask.new("specs") do |t|
|
63
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
64
|
+
t.spec_files = Dir["spec/**/*_spec.rb"].sort
|
65
|
+
end
|
66
|
+
|
67
|
+
##############################################################################
|
68
|
+
# release
|
69
|
+
##############################################################################
|
70
|
+
task :release => [:specs, :package] do
|
71
|
+
sh %{rubyforge add_release canhasgems #{NAME} "#{CanHasSupport::VERSION}" pkg/#{NAME}-#{CanHasSupport::VERSION}.gem}
|
72
|
+
%w[zip tgz].each do |ext|
|
73
|
+
sh %{rubyforge add_file canhasgems #{NAME} #{CanHasSupport::VERSION} pkg/#{NAME}-#{CanHasSupport::VERSION}.#{ext}}
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Fixnum
|
2
|
+
{"years" => 31536000,"weeks" => 604800,"days" => 86400,
|
3
|
+
"hours" => 3600,"minutes" => 60, "seconds" => 1}.each do |key,val|
|
4
|
+
define_method( key ){ self * val }
|
5
|
+
end
|
6
|
+
|
7
|
+
%w(year week day hour minute second).each do |method|
|
8
|
+
define_method( method ){ 1.send("#{method}s".to_sym) }
|
9
|
+
end
|
10
|
+
|
11
|
+
{"ago" => "-", "from_now" => "+"}.each do |key,val|
|
12
|
+
define_method( key ){ Time.now.send(val.to_sym,self) }
|
13
|
+
end
|
14
|
+
|
15
|
+
{"until" => "-","since" => "+"}.each do |key,val|
|
16
|
+
define_method( key ){ |time| time.send(val.to_sym,self) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Hash
|
2
|
+
## These are stealed from Geoff of Peepcode fame
|
3
|
+
##
|
4
|
+
# Filter keys out of a Hash.
|
5
|
+
#
|
6
|
+
# { :a => 1, :b => 2, :c => 3 }.except(:a)
|
7
|
+
# => { :b => 2, :c => 3 }
|
8
|
+
def except(*keys)
|
9
|
+
self.reject { |k,v| keys.include?(k || k.to_sym) }
|
10
|
+
end
|
11
|
+
##
|
12
|
+
# Override some keys.
|
13
|
+
#
|
14
|
+
# { :a => 1, :b => 2, :c => 3 }.with(:a => 4)
|
15
|
+
# => { :a => 4, :b => 2, :c => 3 }
|
16
|
+
def with(overrides = {})
|
17
|
+
self.merge overrides
|
18
|
+
end
|
19
|
+
##
|
20
|
+
# Returns a Hash with only the pairs identified by +keys+.
|
21
|
+
#
|
22
|
+
# { :a => 1, :b => 2, :c => 3 }.only(:a)
|
23
|
+
# => { :a => 1 }
|
24
|
+
def only(*keys)
|
25
|
+
self.reject { |k,v| !keys.include?(k || k.to_sym) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Range
|
2
|
+
##
|
3
|
+
# Takes a range and converts it to an array of days
|
4
|
+
#
|
5
|
+
# (Time.now..7.days.from_now).to_days
|
6
|
+
#
|
7
|
+
def to_days
|
8
|
+
return if first > last
|
9
|
+
arr = []
|
10
|
+
time = first
|
11
|
+
while time <= last
|
12
|
+
arr << time
|
13
|
+
time += 1.day
|
14
|
+
end
|
15
|
+
return arr
|
16
|
+
end
|
17
|
+
##
|
18
|
+
# Takes a range and converts it to an array of hours
|
19
|
+
#
|
20
|
+
# (Time.now..1.day.from_now).to_hours
|
21
|
+
#
|
22
|
+
def to_hours
|
23
|
+
return if first > last
|
24
|
+
arr = []
|
25
|
+
time = first
|
26
|
+
while time <= last
|
27
|
+
arr << time
|
28
|
+
time += 1.hour
|
29
|
+
end
|
30
|
+
return arr
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Time
|
2
|
+
["week","month","year"].each do |time|
|
3
|
+
define_method( "last_#{time}" ){ send(time.to_sym).until(self) }
|
4
|
+
end
|
5
|
+
|
6
|
+
["week","month","year"].each do |time|
|
7
|
+
define_method( "next_#{time}" ){ 1.send(time.to_sym).since(self) }
|
8
|
+
end
|
9
|
+
##
|
10
|
+
# Convience methods
|
11
|
+
def tomorrow
|
12
|
+
1.day.since(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def yesterday
|
16
|
+
1.day.until(self)
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: can_has_support
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors: []
|
7
|
+
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-17 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- LICENSE
|
27
|
+
- HISTORY
|
28
|
+
- README
|
29
|
+
- lib/can_has_support
|
30
|
+
- lib/can_has_support/fixnum_time_ext.rb
|
31
|
+
- lib/can_has_support/hash_core_ext.rb
|
32
|
+
- lib/can_has_support/range_time_ext.rb
|
33
|
+
- lib/can_has_support/time_core_ext.rb
|
34
|
+
- lib/can_has_support/version.rb
|
35
|
+
- lib/can_has_support.rb
|
36
|
+
has_rdoc: false
|
37
|
+
homepage:
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.0.1
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: ""
|
62
|
+
test_files: []
|
63
|
+
|