mongoid-friendly-timestamps 0.0.1 → 0.0.2

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/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
+ .redcar
4
+ .rvmrc
3
5
  Gemfile.lock
4
6
  pkg/*
data/README ADDED
@@ -0,0 +1,13 @@
1
+ Adds a 'friendly_timestamp' method with which you can define a pair of linked
2
+ timestamp fields (one a raw float for precision, the other a human-readable string). For example:
3
+
4
+ class MyDocument
5
+ include Mongoid::Document
6
+ include Mongoid::Friendly::Timestamps
7
+
8
+ friendly_timestamp :timestamp, :friendly_timestamp
9
+ end
10
+
11
+ doc = MyDocument.new
12
+ doc.timestamp = Time.now
13
+ # doc.friendly_timestamp == Time.now in 'dd-mmm-yyyy hh:mm:ss.nnnnnnnnn' format
@@ -4,7 +4,18 @@ module Mongoid
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  module ClassMethods
7
- def friendly_timestamp(raw_name, friendly_name)
7
+ def friendly_timestamp(raw_name, *friendly_name)
8
+ args = friendly_name
9
+ friendly_name = args.shift
10
+ raw_options = {}
11
+ friendly_options = {}
12
+
13
+ if friendly_name.is_a? Hash
14
+ raw_options = friendly_name
15
+ friendly_name = args.shift
16
+ end
17
+
18
+ friendly_options = args.shift unless args.empty?
8
19
  update_friendly_field_method_name = "update_friendly_timestamp_field_#{friendly_name}"
9
20
 
10
21
  define_method update_friendly_field_method_name do
@@ -18,8 +29,8 @@ module Mongoid
18
29
  end
19
30
 
20
31
  self.class_eval do
21
- field raw_name, :type => Float
22
- field friendly_name, :type => String
32
+ field raw_name, raw_options.merge(:type => Float)
33
+ field friendly_name, friendly_options.merge(:type => String)
23
34
 
24
35
  before_validation { self.send(update_friendly_field_method_name) }
25
36
  end
@@ -1,7 +1,7 @@
1
1
  module Mongoid
2
2
  module Friendly
3
3
  module Timestamps
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -10,19 +10,9 @@ Gem::Specification.new do |s|
10
10
  s.email = ["lee.m.henson@gmail.com"]
11
11
  s.homepage = "http://www.musicglue.com"
12
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}
13
+ s.description = %q{Adds a 'friendly_timestamp' method with which you can define a pair of
14
+ linkedtimestamp fields (one a raw float for precision, the other a
15
+ human-readable string). See README for details.}
26
16
 
27
17
  s.rubyforge_project = "mongoid-friendly-timestamps"
28
18
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid-friendly-timestamps
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lee Henson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-09 00:00:00 +00:00
13
+ date: 2011-02-10 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -25,19 +25,9 @@ dependencies:
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
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
28
+ Adds a 'friendly_timestamp' method with which you can define a pair of
29
+ linkedtimestamp fields (one a raw float for precision, the other a
30
+ human-readable string). See README for details.
41
31
  email:
42
32
  - lee.m.henson@gmail.com
43
33
  executables: []
@@ -49,6 +39,7 @@ extra_rdoc_files: []
49
39
  files:
50
40
  - .gitignore
51
41
  - Gemfile
42
+ - README
52
43
  - Rakefile
53
44
  - lib/mongoid-friendly-timestamps.rb
54
45
  - lib/mongoid-friendly-timestamps/version.rb