mongoid_touch 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm use --create 1.9.2@mongoid_touch
2
+
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm: 1.9.2
2
+
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "mongoid"
4
+
5
+ group :development, :test do
6
+ gem "rake"
7
+ gem "rspec", "~> 2.3.0"
8
+ gem "mongoid-rspec"
9
+ gem "bson_ext"
10
+ gem "database_cleaner"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ end
14
+
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.9)
5
+ activesupport (= 3.0.9)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activesupport (3.0.9)
9
+ bson (1.3.1)
10
+ bson_ext (1.3.1)
11
+ builder (2.1.2)
12
+ database_cleaner (0.6.7)
13
+ diff-lcs (1.1.2)
14
+ git (1.2.5)
15
+ i18n (0.5.0)
16
+ jeweler (1.6.4)
17
+ bundler (~> 1.0)
18
+ git (>= 1.2.5)
19
+ rake
20
+ mongo (1.3.1)
21
+ bson (>= 1.3.1)
22
+ mongoid (2.1.7)
23
+ activemodel (~> 3.0)
24
+ mongo (~> 1.3)
25
+ tzinfo (~> 0.3.22)
26
+ mongoid-rspec (1.4.4)
27
+ mongoid (~> 2.0)
28
+ rspec (~> 2)
29
+ rake (0.9.2)
30
+ rspec (2.3.0)
31
+ rspec-core (~> 2.3.0)
32
+ rspec-expectations (~> 2.3.0)
33
+ rspec-mocks (~> 2.3.0)
34
+ rspec-core (2.3.1)
35
+ rspec-expectations (2.3.0)
36
+ diff-lcs (~> 1.1.2)
37
+ rspec-mocks (2.3.0)
38
+ tzinfo (0.3.29)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bson_ext
45
+ bundler (~> 1.0.0)
46
+ database_cleaner
47
+ jeweler (~> 1.6.4)
48
+ mongoid
49
+ mongoid-rspec
50
+ rake
51
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Christoph Grabo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = mongoid_touch
2
+
3
+ A tiny mongoid extension to provide the `touch` method known from ActiveRecord to Mongoid::Document.
4
+
5
+ == Contributing to mongoid_touch
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Christoph Grabo. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "mongoid_touch"
19
+ gem.homepage = "http://github.com/asaaki/mongoid_touch"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Mongoid::Document with a touch method}
22
+ gem.description = %Q{A tiny mongoid extension to provide the `touch` method known from ActiveRecord to Mongoid::Document.}
23
+ gem.email = "chris@dinarrr.com"
24
+ gem.authors = ["Christoph Grabo"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ end
38
+
39
+ task :default => :spec
40
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ module Mongoid
4
+ module Errors
5
+ class MissingField < MongoidError
6
+ def initialize(name)
7
+ super(
8
+ translate("missing_field", { :name => name })
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require "mongoid/errors/missing_field"
4
+
5
+ module Mongoid
6
+ module Document
7
+ def touch( at_field = nil )
8
+ to_touch = at_field || :updated_at
9
+ if self.fields.include? to_touch.to_s
10
+ self.update_attribute(to_touch.to_sym, Time.now.utc)
11
+ else
12
+ raise Errors::MissingField.new(to_touch.to_s)
13
+ end
14
+ end
15
+ alias :touch! :touch
16
+ end
17
+ end
18
+
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mongoid_touch}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Christoph Grabo}]
12
+ s.date = %q{2011-08-14}
13
+ s.description = %q{A tiny mongoid extension to provide the `touch` method known from ActiveRecord to Mongoid::Document.}
14
+ s.email = %q{chris@dinarrr.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".rvmrc",
23
+ ".travis.yml",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "lib/mongoid/errors/missing_field.rb",
31
+ "lib/mongoid_touch.rb",
32
+ "mongoid_touch.gemspec",
33
+ "spec/mongoid_touch_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/asaaki/mongoid_touch}
37
+ s.licenses = [%q{MIT}]
38
+ s.require_paths = [%q{lib}]
39
+ s.rubygems_version = %q{1.8.6}
40
+ s.summary = %q{Mongoid::Document with a touch method}
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<mongoid>, [">= 0"])
47
+ s.add_development_dependency(%q<rake>, [">= 0"])
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
49
+ s.add_development_dependency(%q<mongoid-rspec>, [">= 0"])
50
+ s.add_development_dependency(%q<bson_ext>, [">= 0"])
51
+ s.add_development_dependency(%q<database_cleaner>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
54
+ else
55
+ s.add_dependency(%q<mongoid>, [">= 0"])
56
+ s.add_dependency(%q<rake>, [">= 0"])
57
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
58
+ s.add_dependency(%q<mongoid-rspec>, [">= 0"])
59
+ s.add_dependency(%q<bson_ext>, [">= 0"])
60
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<mongoid>, [">= 0"])
66
+ s.add_dependency(%q<rake>, [">= 0"])
67
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
68
+ s.add_dependency(%q<mongoid-rspec>, [">= 0"])
69
+ s.add_dependency(%q<bson_ext>, [">= 0"])
70
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
73
+ end
74
+ end
75
+
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+
5
+ class TestDoc
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+ field :name, type: String
9
+ end
10
+
11
+ class TestDocTwo
12
+ include Mongoid::Document
13
+ field :name, type: String
14
+ field :modified_at, type: Time
15
+ end
16
+
17
+ describe "Mongoid::Document#touch" do
18
+
19
+ it "should update the updated_at field" do
20
+ doc = TestDoc.create(name: "My test doc")
21
+ origin_at = doc.updated_at
22
+ sleep 1
23
+ doc.touch
24
+ doc.updated_at.should > origin_at
25
+ end
26
+
27
+ it "should update a custom Time field" do
28
+ doc = TestDocTwo.create(name: "My test doc", modified_at: Time.now.utc)
29
+ origin_at = doc.modified_at
30
+ sleep 1
31
+ doc.touch(:modified_at)
32
+ doc.modified_at.should > origin_at
33
+ end
34
+
35
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
6
+ require 'database_cleaner'
7
+ require 'mongoid'
8
+ require 'mongoid-rspec'
9
+ require 'mongoid_touch'
10
+
11
+ RSpec.configure do |config|
12
+ config.include Mongoid::Matchers
13
+ config.before(:suite) do
14
+ DatabaseCleaner.strategy = :truncation
15
+ end
16
+
17
+ config.after(:each) do
18
+ DatabaseCleaner.clean
19
+ end
20
+ end
21
+
22
+ Mongoid.configure do |config|
23
+ config.master = Mongo::Connection.new.db("mongoid_touch_test")
24
+ end
25
+
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_touch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christoph Grabo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: &27509280 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *27509280
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &27508780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *27508780
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &27508220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.3.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *27508220
47
+ - !ruby/object:Gem::Dependency
48
+ name: mongoid-rspec
49
+ requirement: &27487340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *27487340
58
+ - !ruby/object:Gem::Dependency
59
+ name: bson_ext
60
+ requirement: &27486640 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *27486640
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: &27486100 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *27486100
80
+ - !ruby/object:Gem::Dependency
81
+ name: bundler
82
+ requirement: &27485400 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.0.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *27485400
91
+ - !ruby/object:Gem::Dependency
92
+ name: jeweler
93
+ requirement: &27484840 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.6.4
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *27484840
102
+ description: A tiny mongoid extension to provide the `touch` method known from ActiveRecord
103
+ to Mongoid::Document.
104
+ email: chris@dinarrr.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files:
108
+ - LICENSE.txt
109
+ - README.rdoc
110
+ files:
111
+ - .document
112
+ - .rspec
113
+ - .rvmrc
114
+ - .travis.yml
115
+ - Gemfile
116
+ - Gemfile.lock
117
+ - LICENSE.txt
118
+ - README.rdoc
119
+ - Rakefile
120
+ - VERSION
121
+ - lib/mongoid/errors/missing_field.rb
122
+ - lib/mongoid_touch.rb
123
+ - mongoid_touch.gemspec
124
+ - spec/mongoid_touch_spec.rb
125
+ - spec/spec_helper.rb
126
+ homepage: http://github.com/asaaki/mongoid_touch
127
+ licenses:
128
+ - MIT
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ segments:
140
+ - 0
141
+ hash: 4468344717250888768
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.6
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Mongoid::Document with a touch method
154
+ test_files: []