jakewendt-stringify_time 1.0.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/README.rdoc +21 -0
- data/lib/stringify_time.rb +37 -0
- metadata +83 -0
data/README.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= StringifyTime
|
2
|
+
|
3
|
+
Introduction goes here.
|
4
|
+
|
5
|
+
== Attempting Gemification with Jeweler
|
6
|
+
|
7
|
+
vi Rakefile
|
8
|
+
rake version:write
|
9
|
+
rake gemspec
|
10
|
+
rake install
|
11
|
+
|
12
|
+
|
13
|
+
rake version:bump:major
|
14
|
+
rake release
|
15
|
+
|
16
|
+
== Example
|
17
|
+
|
18
|
+
Example goes here.
|
19
|
+
|
20
|
+
|
21
|
+
Copyright (c) 2008 [Jake Wendt], released under the MIT license
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# StringifyTime
|
2
|
+
|
3
|
+
## models/task.rb
|
4
|
+
#stringify_time :due_at
|
5
|
+
#
|
6
|
+
#def validate
|
7
|
+
# errors.add(:due_at, "is invalid") if due_at_invalid?
|
8
|
+
#end
|
9
|
+
|
10
|
+
# stringify_time.rb
|
11
|
+
module StringifyTime
|
12
|
+
def stringify_time(*names)
|
13
|
+
names.each do |name|
|
14
|
+
define_method "#{name}_string" do
|
15
|
+
read_attribute(name).to_s(:db) unless read_attribute(name).nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method "#{name}_string=" do |time_str|
|
19
|
+
begin
|
20
|
+
# write_attribute(name, Time.parse(time_str))
|
21
|
+
# Chronic.parse will not raise an error to rescue from
|
22
|
+
# chronic actually returns a time
|
23
|
+
time = Chronic.parse(time_str)
|
24
|
+
raise ArgumentError if time.nil?
|
25
|
+
write_attribute(name, time)
|
26
|
+
rescue ArgumentError
|
27
|
+
instance_variable_set("@#{name}_invalid", true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
define_method "#{name}_invalid?" do
|
32
|
+
instance_variable_get("@#{name}_invalid")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
ActiveRecord::Base.send(:extend, StringifyTime)
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jakewendt-stringify_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jake
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-17 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: chronic
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 17
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
version: 0.2.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: longer description of your gem
|
38
|
+
email: github@jake.otherinbox.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- lib/stringify_time.rb
|
47
|
+
- README.rdoc
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/jakewendt/stringify_time
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.7
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: one-line summary of your gem
|
82
|
+
test_files: []
|
83
|
+
|