attr-chain 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ben Schwarz
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.
@@ -0,0 +1,31 @@
1
+ # attr-chain
2
+
3
+ `attr-chain` is for when you're building up a `DSL` in which you'd like to have attributes
4
+ that can be chained together when they're being set.
5
+
6
+ Its simple and small, you probably aren't interested. I kept on using this pattern and wanted to abstract it away from my other code.
7
+
8
+ ## Working example
9
+
10
+ require 'attr-chain'
11
+ class Chainsaw
12
+ include AttributeChain
13
+ attr_chain :start, :cut
14
+ end
15
+
16
+ >> c = Chainsaw.new
17
+
18
+ >> c.start
19
+ => nil
20
+
21
+ >> c.start(:now).cut(:hippy)
22
+ >> c.start
23
+ => :now
24
+
25
+ >> c.cut
26
+ => :hippy
27
+
28
+ ### Copyright
29
+
30
+ Copyright (c) 2009 Ben Schwarz. See LICENSE for details.
31
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 2
@@ -0,0 +1,21 @@
1
+ module AttributeChain
2
+ def self.included(base)
3
+ base.extend(ClassMethods)
4
+ end
5
+
6
+ module ClassMethods
7
+ def attr_chain(*methods)
8
+ methods.each do |m|
9
+ define_method(m) do |set|
10
+ ivar = "@#{m}"
11
+ unless set.nil?
12
+ instance_variable_set(ivar, set)
13
+ return self
14
+ else
15
+ return instance_variable_get(ivar)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe AttributeChain do
4
+ before :all do
5
+ class Foo
6
+ include AttributeChain
7
+ attr_chain :spec
8
+ end
9
+
10
+ @instance = Foo.new
11
+ end
12
+
13
+ it "should respond to :attr_chain" do
14
+ Foo.should respond_to(:attr_chain)
15
+ end
16
+
17
+ it "should have a method for :spec" do
18
+ @instance.should respond_to(:spec)
19
+ end
20
+
21
+ it "should allow setting :spec" do
22
+ @instance.spec("aye")
23
+ end
24
+
25
+ it "should be set" do
26
+ @instance.spec("aye")
27
+ @instance.spec.should == "aye"
28
+ end
29
+
30
+ it "should return an instance of the Foo class after setting :spec" do
31
+ @instance.spec("aye").should be_an_instance_of(Foo)
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ -c
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'attr_chain'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attr-chain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Ben Schwarz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-08 00:00:00 +10:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ben.schwarz@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.md
24
+ - LICENSE
25
+ files:
26
+ - README.md
27
+ - VERSION.yml
28
+ - lib/attr-chain.rb
29
+ - spec/attr_method_spec.rb
30
+ - spec/spec.opts
31
+ - spec/spec_helper.rb
32
+ - LICENSE
33
+ has_rdoc: true
34
+ homepage: http://github.com/benschwarz/attr-chain
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --inline-source
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.5
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: attr_chain for chainable, single method attribute (get|setters)
62
+ test_files: []
63
+