chain-boy 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/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/chain-boy.gemspec +18 -0
- data/lib/chain-boy.rb +4 -0
- data/lib/chain-boy/dynamic_delegator.rb +11 -0
- data/lib/chain-boy/version.rb +5 -0
- data/readme.rdoc +26 -0
- data/test/dynamic_delegator_tests.rb +30 -0
- metadata +58 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use ruby-1.9.2@chain-boy
|
data/Gemfile
ADDED
data/Rakefile
ADDED
data/chain-boy.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/chain-boy/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dan Watson"]
|
6
|
+
gem.email = ["dan@dotnetguy.co.uk"]
|
7
|
+
gem.description = %q{Dynamic delegator - created from the information demonstrated in RailsCasts episode 212}
|
8
|
+
gem.summary = %q{Think of DynamicDelegator as a proxy object that passes any calls to it to its target object}
|
9
|
+
gem.homepage = "https://github.com/dotnetguyuk/chain-boy"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "chain-boy"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Chain::Boy::VERSION
|
17
|
+
|
18
|
+
end
|
data/lib/chain-boy.rb
ADDED
data/readme.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
=== Install the gem
|
2
|
+
gem install chain-boy
|
3
|
+
=== Rails Gemfile
|
4
|
+
gem 'chain-boy'
|
5
|
+
|
6
|
+
===So what does it do?
|
7
|
+
|
8
|
+
Turn this :
|
9
|
+
def self.search(params)
|
10
|
+
products = Product.scoped
|
11
|
+
products = products.where("name like ?", "%" + params[:name] + "%") if params[:name]
|
12
|
+
products = products.where("price >= ?", params[:price_gt]) if params[:price_gt]
|
13
|
+
products = products.where("price <= ?", params[:price_lt]) if params[:price_lt]
|
14
|
+
products
|
15
|
+
end
|
16
|
+
|
17
|
+
Info this :
|
18
|
+
|
19
|
+
def self.search(params)
|
20
|
+
products = DynamicDelegator.new(Product.scoped)
|
21
|
+
products.where("name like ?", "%" + params[:name] + "%") if params[:name]
|
22
|
+
products.where("price >= ?", params[:price_gt]) if params[:price_gt]
|
23
|
+
products.where("price <= ?", params[:price_lt]) if params[:price_lt]
|
24
|
+
products
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
|
2
|
+
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'chain-boy'
|
6
|
+
|
7
|
+
|
8
|
+
class DynamicDelegatorTests < Test::Unit::TestCase
|
9
|
+
def test_delegate_method_call
|
10
|
+
adder = DynamicDelegator.new(Adder.new(1))
|
11
|
+
adder.add(1)
|
12
|
+
adder.add(1)
|
13
|
+
assert_equal 3, adder.number
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
class Adder
|
18
|
+
def initialize(number)
|
19
|
+
@number = number
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(number)
|
23
|
+
Adder.new(number + @number)
|
24
|
+
end
|
25
|
+
|
26
|
+
def number
|
27
|
+
@number
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chain-boy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Watson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-29 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Dynamic delegator - created from the information demonstrated in RailsCasts
|
15
|
+
episode 212
|
16
|
+
email:
|
17
|
+
- dan@dotnetguy.co.uk
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- .rvmrc
|
24
|
+
- Gemfile
|
25
|
+
- Rakefile
|
26
|
+
- chain-boy.gemspec
|
27
|
+
- lib/chain-boy.rb
|
28
|
+
- lib/chain-boy/dynamic_delegator.rb
|
29
|
+
- lib/chain-boy/version.rb
|
30
|
+
- readme.rdoc
|
31
|
+
- test/dynamic_delegator_tests.rb
|
32
|
+
homepage: https://github.com/dotnetguyuk/chain-boy
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.6
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Think of DynamicDelegator as a proxy object that passes any calls to it to
|
56
|
+
its target object
|
57
|
+
test_files:
|
58
|
+
- test/dynamic_delegator_tests.rb
|