collector 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 ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :test do
4
+ gem "turn", "~> 0.9.6"
5
+ gem "minitest", "~> 4.1.0"
6
+ gem "mocha", "~> 0.12.7", require: false
7
+ gem "timecop", "~> 0.5.3"
8
+ end
9
+
10
+ # Specify your gem's dependencies in collector.gemspec
11
+ gemspec
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
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.pattern = "test/**/*_spec.rb"
8
+ end
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,15 @@
1
+ require "collector/version"
2
+
3
+ require "collector/model"
4
+
5
+ module Collector
6
+
7
+ def self.connection
8
+ @@connection
9
+ end
10
+
11
+ def self.connection=(connection)
12
+ @@connection = connection
13
+ end
14
+
15
+ end
@@ -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,3 @@
1
+ module Collector
2
+ VERSION = "0.0.2"
3
+ 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
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../test_helper.rb", __FILE__)
2
+
3
+ describe Collector do
4
+
5
+ it "has a connection" do
6
+ connection = stub()
7
+ Collector.connection = connection
8
+ Collector.connection.must_equal connection
9
+ end
10
+
11
+ end
@@ -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