herder 0.0.1

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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@hamster --create
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+
3
+ branches:
4
+ only:
5
+ - master
6
+
7
+ rvm:
8
+ - 1.9.3
9
+
10
+ notifications:
11
+ email:
12
+ - crew@geeksoflondon.com
13
+
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rake"
7
+ end
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ herder (0.0.1)
5
+ active_resource_pagination
6
+ activeresource
7
+ will_paginate
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ active_resource_pagination (0.0.6)
13
+ activemodel (3.2.6)
14
+ activesupport (= 3.2.6)
15
+ builder (~> 3.0.0)
16
+ activeresource (3.2.6)
17
+ activemodel (= 3.2.6)
18
+ activesupport (= 3.2.6)
19
+ activesupport (3.2.6)
20
+ i18n (~> 0.6)
21
+ multi_json (~> 1.0)
22
+ builder (3.0.0)
23
+ diff-lcs (1.1.3)
24
+ i18n (0.6.0)
25
+ multi_json (1.3.6)
26
+ rake (0.9.2.2)
27
+ rspec (2.11.0)
28
+ rspec-core (~> 2.11.0)
29
+ rspec-expectations (~> 2.11.0)
30
+ rspec-mocks (~> 2.11.0)
31
+ rspec-core (2.11.0)
32
+ rspec-expectations (2.11.1)
33
+ diff-lcs (~> 1.1.3)
34
+ rspec-mocks (2.11.1)
35
+ will_paginate (3.0.3)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ herder!
42
+ rake
43
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2012 GeeksOfLondon Ltd <crew@geeksoflondon.com>
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.
23
+
@@ -0,0 +1,54 @@
1
+ # herder
2
+
3
+ [![Build Status](https://secure.travis-ci.org/geeksoflondon/herder.png?branch=master)](http://travis-ci.org/geeksoflondon/herder)
4
+
5
+ The herder that allows all animals to talk to the hamster
6
+
7
+ ## Installation
8
+
9
+ Add to Gemfile for a Rails app:
10
+
11
+ ```ruby
12
+ gem "herder"
13
+ ```
14
+
15
+ Bundle and then add a `config/herder.yml`
16
+
17
+ ```yml
18
+ site: http://localhost:3000/
19
+ user: "username"
20
+ password: "password"
21
+ ```
22
+
23
+ Or don't add the yml file to fall back on the ENV variables `HERDER_SITE`, `HERDER_USER` and `HERDER_PASSWORD`. This is useful for Heroku.
24
+
25
+ ## Usage
26
+
27
+ For now Herder adds a few built in ActiveResource classes. For full usage details read the [ActiveResource documentation](http://api.rubyonrails.org/classes/ActiveResource/Base.html).
28
+
29
+ ```ruby
30
+ Herder::Attendee.find(1)
31
+ #=> #<Attendee:0x007f9aabb84550 @attributes={"created_at"=>"2012-07-10T19:26:23Z", "diet"=>nil, "first_name"=>"John", "id"=>1, "kind"=>1, "last_name"=>"Doe", "name"=>"John Doe", "notes"=>nil, "phone_number"=>nil, "public"=>true, "tshirt"=>nil, "twitter"=>nil, "updated_at"=>"2012-07-10T19:26:23Z"}, @prefix_options={}, @persisted=true>
32
+ ```
33
+
34
+ Alternatively you can make your own models to extend the base classes:
35
+
36
+ ```ruby
37
+ # in app/models/attendee.yml
38
+
39
+ class Attendee < Herder::Attendee
40
+ # add your own convenience methods here
41
+ end
42
+
43
+ # anywhere else
44
+ Attendee.find(1)
45
+ #=> #<Attendee:0x007f9aabb84550 @attributes={"created_at"=>"2012-07-10T19:26:23Z", "diet"=>nil, "first_name"=>"John", "id"=>1, "kind"=>1, "last_name"=>"Doe", "name"=>"John Doe", "notes"=>nil, "phone_number"=>nil, "public"=>true, "tshirt"=>nil, "twitter"=>nil, "updated_at"=>"2012-07-10T19:26:23Z"}, @prefix_options={}, @persisted=true>
46
+ ```
47
+
48
+ ## Changelog
49
+
50
+ * 0.0.1 - Added basic attendee interface
51
+
52
+ ## License
53
+
54
+ See LICENSE
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Set up and run tests"
4
+ task :default => [:test]
5
+
6
+ desc "Run tests"
7
+ task :test do
8
+ sh "bundle exec rspec spec"
9
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "herder/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "herder"
7
+ s.version = Herder::VERSION
8
+ s.authors = ["Cristiano Betta"]
9
+ s.email = ["cristiano@geeksoflondon.com"]
10
+ s.homepage = "http://github.com/geeksoflondon/herder"
11
+ s.summary = "The herder"
12
+ s.description = "The herder that manages all animals talking to the hamster"
13
+
14
+ s.rubyforge_project = "gol-herder"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'rspec'
22
+
23
+ s.add_dependency 'activeresource'
24
+ s.add_dependency 'active_resource_pagination'
25
+ s.add_dependency 'will_paginate'
26
+ end
@@ -0,0 +1,9 @@
1
+ require "active_resource"
2
+ require "active_resource_pagination"
3
+
4
+ require_relative "herder/config"
5
+ require_relative "herder/model"
6
+ require_relative "herder/attendee"
7
+
8
+ class Herder
9
+ end
@@ -0,0 +1,5 @@
1
+ class Herder
2
+ class Attendee < Herder::Model
3
+ self.element_name = "attendee"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ class Herder
2
+ class Config
3
+
4
+ attr_accessor :options
5
+
6
+ def initialize
7
+ self.options = YAML.load_file("config/herder.yml")
8
+ rescue
9
+ self.options = {}
10
+ options["site"] = ENV["HERDER_SITE"] || "http://localhost"
11
+ options["user"] = ENV["HERDER_USER"] || "user"
12
+ options["password"] = ENV["HERDER_PASSWORD"] || "password"
13
+ end
14
+
15
+ def self.get key
16
+ self.instance.options[key]
17
+ end
18
+
19
+ def self.instance
20
+ @instance ||= Herder::Config.new
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ class Herder
2
+ class Model < ActiveResource::Base
3
+ self.site = Herder::Config.get("site")
4
+ self.user = Herder::Config.get("user")
5
+ self.password = Herder::Config.get("password")
6
+
7
+ def self.where options
8
+ find(:all, params: options)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ class Herder
2
+ VERSION = "0.0.1" unless defined? Herder::VERSION
3
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe Herder::Attendee do
4
+ it "should setup right name" do
5
+ Herder::Attendee.element_name.should be == "attendee"
6
+ end
7
+
8
+ it "should inherit Herder::Model" do
9
+ Herder::Attendee.new.should be_a(Herder::Model)
10
+ end
11
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Herder::Config do
4
+
5
+ describe "#initialize" do
6
+ it "should try loading from file" do
7
+ options = {
8
+ "user" => "user2",
9
+ "password" => "password2",
10
+ "site" => "http://localhost2"
11
+
12
+ }
13
+ YAML.should_receive(:load_file).and_return(options)
14
+ config = Herder::Config.new
15
+ config.options["user"].should be == "user2"
16
+ config.options["password"].should be == "password2"
17
+ config.options["site"].should be == "http://localhost2"
18
+ end
19
+
20
+ it "should fall back to env vars" do
21
+ ENV["HERDER_USER"] = "user1"
22
+ ENV["HERDER_PASSWORD"] = "password1"
23
+ ENV["HERDER_SITE"] = "http://localhost1"
24
+ config = Herder::Config.new
25
+ config.options["user"].should be == "user1"
26
+ config.options["password"].should be == "password1"
27
+ config.options["site"].should be == "http://localhost1"
28
+ ENV["HERDER_USER"] = nil
29
+ ENV["HERDER_PASSWORD"] = nil
30
+ ENV["HERDER_SITE"] = nil
31
+ end
32
+
33
+ it "should load defaults as a last resort" do
34
+ config = Herder::Config.new
35
+ config.options["user"].should be == "user"
36
+ config.options["password"].should be == "password"
37
+ config.options["site"].should be == "http://localhost"
38
+ end
39
+ end
40
+
41
+ describe ".instance" do
42
+ it "should only ever create one instance" do
43
+ instance = Herder::Config.instance
44
+ instance.options = {foo: :bar}
45
+ Herder::Config.instance.options.should be == {foo: :bar}
46
+ end
47
+ end
48
+
49
+ describe ".get" do
50
+ it "should return what's in the options" do
51
+ Herder::Config.instance.options = {foo: :bar}
52
+ Herder::Config.get(:foo).should be == :bar
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe Herder::Model do
4
+ it "should setup the remote site" do
5
+ Herder::Model.user.should be == "user"
6
+ Herder::Model.password.should be == "password"
7
+ Herder::Model.site.should be == URI("http://localhost")
8
+ end
9
+
10
+ it "should inherit active resource" do
11
+ Herder::Model.new.should be_a(ActiveResource::Base)
12
+ end
13
+
14
+ describe "#where" do
15
+ it "should pass the query along to find" do
16
+ options = {foo: :bar}
17
+ Herder::Model.should_receive(:find).with(:all, params: options)
18
+ Herder::Model.where(options)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe Herder do
4
+
5
+ end
@@ -0,0 +1 @@
1
+ require "herder"
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: herder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cristiano Betta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70349777641740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70349777641740
25
+ - !ruby/object:Gem::Dependency
26
+ name: activeresource
27
+ requirement: &70349777632640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70349777632640
36
+ - !ruby/object:Gem::Dependency
37
+ name: active_resource_pagination
38
+ requirement: &70349777629560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70349777629560
47
+ - !ruby/object:Gem::Dependency
48
+ name: will_paginate
49
+ requirement: &70349777625780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70349777625780
58
+ description: The herder that manages all animals talking to the hamster
59
+ email:
60
+ - cristiano@geeksoflondon.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .rspec
66
+ - .rvmrc
67
+ - .travis.yml
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE
71
+ - README.md
72
+ - Rakefile
73
+ - herder.gemspec
74
+ - lib/herder.rb
75
+ - lib/herder/attendee.rb
76
+ - lib/herder/config.rb
77
+ - lib/herder/model.rb
78
+ - lib/herder/version.rb
79
+ - spec/herder/attendee_spec.rb
80
+ - spec/herder/config_spec.rb
81
+ - spec/herder/model_spec.rb
82
+ - spec/herder_spec.rb
83
+ - spec/spec_helper.rb
84
+ homepage: http://github.com/geeksoflondon/herder
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project: gol-herder
104
+ rubygems_version: 1.8.10
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: The herder
108
+ test_files:
109
+ - spec/herder/attendee_spec.rb
110
+ - spec/herder/config_spec.rb
111
+ - spec/herder/model_spec.rb
112
+ - spec/herder_spec.rb
113
+ - spec/spec_helper.rb