mongoid-friendly-timestamps 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mongoid-friendly-timestamps.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,30 @@
1
+ module Mongoid
2
+ module Friendly
3
+ module Timestamps
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def friendly_timestamp(raw_name, friendly_name)
8
+ update_friendly_field_method_name = "update_friendly_timestamp_field_#{friendly_name}"
9
+
10
+ define_method update_friendly_field_method_name do
11
+ self[friendly_name] = Time.at(self[raw_name]).strftime '%d-%b-%Y %H:%M:%S.%N'
12
+ end
13
+
14
+ define_method "#{raw_name}=" do |value|
15
+ utc = value.utc
16
+ self[raw_name] = utc.to_f
17
+ self.send update_friendly_field_method_name
18
+ end
19
+
20
+ self.class_eval do
21
+ field raw_name, :type => Float
22
+ field friendly_name, :type => String
23
+
24
+ before_validation { self.send(update_friendly_field_method_name) }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ module Mongoid
2
+ module Friendly
3
+ module Timestamps
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mongoid-friendly-timestamps/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mongoid-friendly-timestamps"
7
+ s.version = Mongoid::Friendly::Timestamps::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Lee Henson"]
10
+ s.email = ["lee.m.henson@gmail.com"]
11
+ s.homepage = "http://www.musicglue.com"
12
+ s.summary = %q{Human-readable, precise mongoid timestamps}
13
+ s.description = %q{Adds a 'friendly_timestamp' method with which you can define a pair of linked
14
+ timestamp fields (one a raw float for precision, the other a human-readable string). For example:
15
+
16
+ class MyDocument
17
+ include Mongoid::Document
18
+ include Mongoid::Friendly::Timestamps
19
+
20
+ friendly_timestamp :timestamp, :friendly_timestamp
21
+ end
22
+
23
+ doc = MyDocument.new
24
+ doc.timestamp = Time.now
25
+ # doc.friendly_timestamp == Time.now in 'dd-mmm-yyyy hh:mm:ss.nnnnnnnnn' format}
26
+
27
+ s.rubyforge_project = "mongoid-friendly-timestamps"
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
+ s.require_paths = ["lib"]
33
+
34
+ s.add_dependency 'activesupport', '~> 3.0.0'
35
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-friendly-timestamps
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Lee Henson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-09 00:00:00 +00:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 3.0.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: |-
28
+ Adds a 'friendly_timestamp' method with which you can define a pair of linked
29
+ timestamp fields (one a raw float for precision, the other a human-readable string). For example:
30
+
31
+ class MyDocument
32
+ include Mongoid::Document
33
+ include Mongoid::Friendly::Timestamps
34
+
35
+ friendly_timestamp :timestamp, :friendly_timestamp
36
+ end
37
+
38
+ doc = MyDocument.new
39
+ doc.timestamp = Time.now
40
+ # doc.friendly_timestamp == Time.now in 'dd-mmm-yyyy hh:mm:ss.nnnnnnnnn' format
41
+ email:
42
+ - lee.m.henson@gmail.com
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files: []
48
+
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - Rakefile
53
+ - lib/mongoid-friendly-timestamps.rb
54
+ - lib/mongoid-friendly-timestamps/version.rb
55
+ - mongoid-friendly-timestamps.gemspec
56
+ has_rdoc: true
57
+ homepage: http://www.musicglue.com
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: mongoid-friendly-timestamps
80
+ rubygems_version: 1.5.0
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Human-readable, precise mongoid timestamps
84
+ test_files: []
85
+