ork-timestamps 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +65 -0
- data/lib/ork/errors.rb +7 -0
- data/lib/ork/timestamps.rb +35 -0
- data/ork-timestamps.gemspec +25 -0
- data/rakefile +10 -0
- data/test/helper.rb +23 -0
- data/test/timestamps_test.rb +88 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e3a4447ac54c2f34109af946b278af6cc9b3294
|
4
|
+
data.tar.gz: d7c56f9257d2448b6c1224a5ea6a4b46e9aa8d04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bd8eaa13b7249165931dc86a74ca1b48f6b7861da149e5518e7e2623211939fe8cba59831dd9b05becb272f7c00314cfc111e0ae79a4091d17b73fba5a5df64
|
7
|
+
data.tar.gz: 2b17dc71d99b051984caf22aadbd22d672f8e860aecaed3b55fc658673ea3aabfae8ac03af21bcf6a5c5cd58a7e7742b1075ac9ce3b372b9c2f68aa826444a3f
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
ork-timestamps
|
2
|
+
==============
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/ork-timestamps.png)](http://badge.fury.io/rb/ork-timestamps)
|
5
|
+
[![Build Status](https://secure.travis-ci.org/emancu/ork-timestamps.png)](http://travis-ci.org/emancu/ork-timestamps)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/emancu/ork-timestamps.png)](https://codeclimate.com/github/emancu/ork-timestamps)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/emancu/ork/badge.png)](https://coveralls.io/r/emancu/ork-timestamps)
|
8
|
+
[![Dependency Status](https://gemnasium.com/emancu/ork-timestamps.png)](https://gemnasium.com/emancu/ork-timestamps)
|
9
|
+
|
10
|
+
|
11
|
+
Timestamps for your Ork Models
|
12
|
+
|
13
|
+
## Dependencies
|
14
|
+
|
15
|
+
`ork-timestamps` requires:
|
16
|
+
|
17
|
+
* Ruby 1.9 or later.
|
18
|
+
* `riak-client` to connect to **Riak**.
|
19
|
+
* `ork` 0.1.3 or later.
|
20
|
+
|
21
|
+
Install Dependencies using `dep` is easy as run:
|
22
|
+
|
23
|
+
$ dep insatll
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Install [Riak](http://basho.com/riak/) with your package manager:
|
28
|
+
|
29
|
+
$ brew install riak
|
30
|
+
|
31
|
+
Or download it from [Riak's download page](http://docs.basho.com/riak/latest/downloads/)
|
32
|
+
|
33
|
+
Once you have it installed, you can execute `riak start` and it will run on `localhost:8098` by default.
|
34
|
+
|
35
|
+
If you don't have `Ork-Timestamps`, try this:
|
36
|
+
|
37
|
+
$ gem install ork-timestamps
|
38
|
+
|
39
|
+
|
40
|
+
## Overview
|
41
|
+
|
42
|
+
`Ork::Timestamps` creates two attributes that automatically set create and update timestamp fields.
|
43
|
+
|
44
|
+
## Getting started
|
45
|
+
|
46
|
+
Include `Ork::Timestamps` module in your `Ork::Document` class.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
class SomeDocument
|
50
|
+
include Ork::Document
|
51
|
+
include Ork::Timestamps
|
52
|
+
|
53
|
+
attribute :message
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Enjoy your models with timestamps!
|
58
|
+
|
59
|
+
## Running the Tests
|
60
|
+
|
61
|
+
Adjust the variable to point to a test riak database. Default is `http://localhost:8098`
|
62
|
+
|
63
|
+
```bash
|
64
|
+
$ ORK_RIAK_URL='http://localhost:8198' rake
|
65
|
+
```
|
data/lib/ork/errors.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'errors'
|
2
|
+
|
3
|
+
module Ork
|
4
|
+
module Timestamps
|
5
|
+
VERSION = '0.0.1'
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
raise NotAnOrkDocument unless klass.included_modules.include? Ork::Document
|
9
|
+
|
10
|
+
klass.class_eval do |base|
|
11
|
+
attribute :created_at, accessors: :reader
|
12
|
+
attribute :updated_at, accessors: :reader
|
13
|
+
|
14
|
+
def created_at=(a)
|
15
|
+
@attributes[:created_at] = Time.parse a.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def updated_at=(a)
|
19
|
+
@attributes[:updated_at] = Time.parse a.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def save_with_timestamps
|
23
|
+
self.created_at = Time.now if self.new?
|
24
|
+
self.updated_at = Time.now
|
25
|
+
|
26
|
+
save_without_timestamps
|
27
|
+
end
|
28
|
+
|
29
|
+
alias :save_without_timestamps :save
|
30
|
+
alias :save :save_with_timestamps
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ork-timestamps'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
5
|
+
s.summary = 'A simple library to add timestamps to Ork::Documents stored in riak.'
|
6
|
+
s.description = 'Add the clasic timestamps :created_at, :updated_at to the Ork::Documents'
|
7
|
+
s.authors = ['Emiliano Mancuso']
|
8
|
+
s.email = ['emiliano.mancuso@gmail.com']
|
9
|
+
s.homepage = 'http://github.com/emancu/ork-timestamps'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.files = Dir[
|
13
|
+
'README.md',
|
14
|
+
'rakefile',
|
15
|
+
'lib/**/*.rb',
|
16
|
+
'*.gemspec'
|
17
|
+
]
|
18
|
+
s.test_files = Dir['test/*.*']
|
19
|
+
|
20
|
+
s.add_runtime_dependency 'riak-client', '~> 1.4'
|
21
|
+
s.add_runtime_dependency 'ork', '~> 0.1', '>= 0.1.3'
|
22
|
+
s.add_development_dependency 'protest', '~> 0'
|
23
|
+
s.add_development_dependency 'coveralls', '~> 0'
|
24
|
+
end
|
25
|
+
|
data/rakefile
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
2
|
+
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
project_name "Ork-Timestamps"
|
8
|
+
command_name "Protest"
|
9
|
+
|
10
|
+
add_filter "/test/"
|
11
|
+
end
|
12
|
+
|
13
|
+
require "rubygems"
|
14
|
+
require "protest"
|
15
|
+
require "ork"
|
16
|
+
require 'ork/timestamps'
|
17
|
+
|
18
|
+
Riak.disable_list_keys_warnings = true
|
19
|
+
Protest.report_with(:progress)
|
20
|
+
|
21
|
+
def deny(condition, message="Expected condition to be unsatisfied")
|
22
|
+
assert !condition, message
|
23
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class Event
|
4
|
+
include Ork::Document
|
5
|
+
include Ork::Timestamps
|
6
|
+
|
7
|
+
attribute :name
|
8
|
+
end
|
9
|
+
|
10
|
+
Protest.describe 'Ork::Timestamps' do
|
11
|
+
context 'include Ork::Timestamps' do
|
12
|
+
test 'raise an error if it is not a Ork::Document' do
|
13
|
+
assert_raise Ork::Timestamps::NotAnOrkDocument do
|
14
|
+
class NotADocument
|
15
|
+
include Ork::Timestamps
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'add timestamps attributes' do
|
21
|
+
assert Event.attributes.include? :created_at
|
22
|
+
assert Event.attributes.include? :updated_at
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'created_at' do
|
26
|
+
setup do
|
27
|
+
@event = Event.new name: 'Birthday'
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'is not setted if save was not called' do
|
31
|
+
deny @event.created_at
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'is setted on creation' do
|
35
|
+
@event.save
|
36
|
+
|
37
|
+
assert @event.created_at
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'is not updated on each save' do
|
41
|
+
@event.save
|
42
|
+
prev_created_at = @event.created_at
|
43
|
+
@event.save
|
44
|
+
|
45
|
+
assert @event.created_at == prev_created_at
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'retrieve the object returns a Time object' do
|
49
|
+
@event.save
|
50
|
+
same_event = Event[@event.id]
|
51
|
+
|
52
|
+
assert_equal @event.created_at, same_event.created_at
|
53
|
+
assert_equal Time, same_event.created_at.class
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'updated_at' do
|
58
|
+
setup do
|
59
|
+
@event = Event.new name: 'Birthday'
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'is not setted if save was not called' do
|
63
|
+
deny @event.updated_at
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'is setted on creation' do
|
67
|
+
@event.save
|
68
|
+
|
69
|
+
assert @event.updated_at
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'is updated on each save' do
|
73
|
+
prev_updated_at = @event.updated_at
|
74
|
+
@event.save
|
75
|
+
|
76
|
+
assert @event.updated_at != prev_updated_at
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'retrieve the object returns a Time object' do
|
80
|
+
@event.save
|
81
|
+
same_event = Event[@event.id]
|
82
|
+
|
83
|
+
assert_equal @event.updated_at, same_event.updated_at
|
84
|
+
assert_equal Time, same_event.updated_at.class
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ork-timestamps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emiliano Mancuso
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: riak-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ork
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.1.3
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.1'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.1.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: protest
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: coveralls
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: Add the clasic timestamps :created_at, :updated_at to the Ork::Documents
|
76
|
+
email:
|
77
|
+
- emiliano.mancuso@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- README.md
|
83
|
+
- lib/ork/errors.rb
|
84
|
+
- lib/ork/timestamps.rb
|
85
|
+
- ork-timestamps.gemspec
|
86
|
+
- rakefile
|
87
|
+
- test/helper.rb
|
88
|
+
- test/timestamps_test.rb
|
89
|
+
homepage: http://github.com/emancu/ork-timestamps
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A simple library to add timestamps to Ork::Documents stored in riak.
|
113
|
+
test_files:
|
114
|
+
- test/helper.rb
|
115
|
+
- test/timestamps_test.rb
|