collector 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/collector.gemspec +19 -0
- data/lib/collector.rb +15 -0
- data/lib/collector/model.rb +25 -0
- data/lib/collector/version.rb +3 -0
- data/test/collector/model_spec.rb +66 -0
- data/test/collector_spec.rb +11 -0
- data/test/test_helper.rb +17 -0
- metadata +60 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brandon Weiss
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Collector
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'collector'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install collector
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/collector.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'collector/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "collector"
|
8
|
+
gem.version = Collector::VERSION
|
9
|
+
gem.authors = ["Brandon Weiss"]
|
10
|
+
gem.email = ["brandon@anti-pattern.com"]
|
11
|
+
gem.description = %q{An implementation of the Repository Pattern}
|
12
|
+
gem.summary = %q{An implementation of the Repository Pattern}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/collector.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Collector
|
2
|
+
module Model
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
attr_reader :created_at, :updated_at
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
attributes.each do |attribute, value|
|
10
|
+
send("#{attribute}=", value) if methods.include? "#{attribute}=".to_sym
|
11
|
+
end
|
12
|
+
|
13
|
+
created_at = attributes["created_at"] || attributes[:created_at]
|
14
|
+
updated_at = attributes["updated_at"] || attributes[:updated_at]
|
15
|
+
instance_variable_set("@created_at", created_at) if created_at
|
16
|
+
instance_variable_set("@updated_at", updated_at) if updated_at
|
17
|
+
end
|
18
|
+
|
19
|
+
def touch
|
20
|
+
@created_at ||= Time.now.utc
|
21
|
+
@updated_at = Time.now.utc
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.expand_path("../../test_helper.rb", __FILE__)
|
2
|
+
|
3
|
+
describe Collector::Model do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Object.send(:remove_const, :TestModel) if Object.const_defined?(:TestModel)
|
7
|
+
class TestModel
|
8
|
+
include Collector::Model
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets attributes during initialization if a writer exists" do
|
13
|
+
TestModel.send(:attr_reader, :foo)
|
14
|
+
TestModel.send(:attr_writer, :foo)
|
15
|
+
TestModel.new(foo: "bar").foo.must_equal "bar"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "does not set attributes during initialization if a writer does not exist" do
|
19
|
+
TestModel.send(:attr_reader, :foo)
|
20
|
+
TestModel.new(foo: "bar").foo.must_be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has a created_at and updated_at timestamp" do
|
24
|
+
now = Time.now
|
25
|
+
test_model = TestModel.new
|
26
|
+
test_model.instance_variable_set("@created_at", now)
|
27
|
+
test_model.created_at.must_equal now
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sets timestamps via instance variables during initialization" do
|
31
|
+
now = Time.now
|
32
|
+
test_model = TestModel.new(created_at: now, updated_at: now)
|
33
|
+
test_model.created_at.must_equal now
|
34
|
+
test_model.updated_at.must_equal now
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "touch" do
|
38
|
+
|
39
|
+
it "sets the timestamps" do
|
40
|
+
Timecop.freeze
|
41
|
+
|
42
|
+
test_model = TestModel.new
|
43
|
+
test_model.touch
|
44
|
+
test_model.created_at.must_equal Time.now.utc
|
45
|
+
test_model.updated_at.must_equal Time.now.utc
|
46
|
+
test_model.created_at.utc?.must_equal true
|
47
|
+
test_model.updated_at.utc?.must_equal true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "does not set the created_at if it's already been set" do
|
51
|
+
Timecop.freeze
|
52
|
+
|
53
|
+
now = Time.now
|
54
|
+
test_model = TestModel.new
|
55
|
+
test_model.touch
|
56
|
+
test_model.created_at.must_equal now.utc
|
57
|
+
|
58
|
+
Timecop.travel(Time.now + 1000)
|
59
|
+
test_model.touch
|
60
|
+
|
61
|
+
test_model.created_at.must_equal now.utc
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
|
5
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
6
|
+
require "collector"
|
7
|
+
|
8
|
+
require "minitest/autorun"
|
9
|
+
require "mocha"
|
10
|
+
|
11
|
+
class MiniTest::Spec
|
12
|
+
|
13
|
+
after do
|
14
|
+
Timecop.return
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brandon Weiss
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: An implementation of the Repository Pattern
|
15
|
+
email:
|
16
|
+
- brandon@anti-pattern.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- collector.gemspec
|
27
|
+
- lib/collector.rb
|
28
|
+
- lib/collector/model.rb
|
29
|
+
- lib/collector/version.rb
|
30
|
+
- test/collector/model_spec.rb
|
31
|
+
- test/collector_spec.rb
|
32
|
+
- test/test_helper.rb
|
33
|
+
homepage: ''
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.23
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: An implementation of the Repository Pattern
|
57
|
+
test_files:
|
58
|
+
- test/collector/model_spec.rb
|
59
|
+
- test/collector_spec.rb
|
60
|
+
- test/test_helper.rb
|