acts_as_chain 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ -fs
3
+ -Ilib
4
+ -Ispec
5
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in acts_as_chain.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/Readme.md ADDED
@@ -0,0 +1,27 @@
1
+ # Acts as chain
2
+
3
+ Define a set methods that should be chainable.
4
+
5
+ ## Example
6
+
7
+ ``` ruby
8
+ require "acts_as_chain"
9
+
10
+ class MyExampleClass
11
+ acts_as_chain :method1, :method2
12
+ end
13
+
14
+ MyExampleClass.new.method1("value1").method2("value2").method1 # => "value1"
15
+ ```
16
+
17
+ ## Installation
18
+
19
+ [sudo] gem install acts_as_chain
20
+
21
+ ## Requirements
22
+
23
+ *acts_as_chain* is tested in *OS X 10.7.2* using Ruby *1.9.2*, *1.8.7*.
24
+
25
+ ## License
26
+
27
+ *acts_as_chain* is released under the *MIT license*.
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/acts_as_chain/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Linus Oleander"]
6
+ gem.email = ["linus@oleander.nu"]
7
+ gem.description = %q{Define a set methods that should be chainable}
8
+ gem.summary = %q{Define a set methods that should be chainable}
9
+ gem.homepage = "https://github.com/oleander/acts_as_chain"
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 = "acts_as_chain"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ActsAsChain::VERSION
17
+
18
+ gem.add_development_dependency("rspec")
19
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsChain
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ require "acts_as_chain/version"
2
+
3
+ class Object
4
+ def self.acts_as_chain(*args)
5
+ args.each do |method|
6
+ define_method method do |*args|
7
+ if args.empty?
8
+ instance_variable_get("@#{method.to_s}")
9
+ else
10
+ tap {
11
+ instance_variable_set("@#{method.to_s}", args.first)
12
+ }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ describe ActsAsChain do
2
+ let(:object) {
3
+ class FakeObject
4
+ acts_as_chain :fake1, :fake2
5
+ end
6
+
7
+ FakeObject.new
8
+ }
9
+
10
+ it "should be chainable" do
11
+ object.fake1("value").fake1.should eq("value")
12
+ end
13
+
14
+ it "should have a get method" do
15
+ object.fake1.should be_nil
16
+ end
17
+
18
+ it "should be able to handle more than one chain" do
19
+ object.fake1("one").fake2("two")
20
+ object.fake1.should eq("one")
21
+ object.fake2.should eq("two")
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require "rspec"
2
+ require "acts_as_chain"
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rspec
6
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_chain
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Linus Oleander
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-22 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: Define a set methods that should be chainable
27
+ email:
28
+ - linus@oleander.nu
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - .rspec
38
+ - Gemfile
39
+ - Rakefile
40
+ - Readme.md
41
+ - acts_as_chain.gemspec
42
+ - lib/acts_as_chain.rb
43
+ - lib/acts_as_chain/version.rb
44
+ - spec/acts_as_chain_spec.rb
45
+ - spec/spec_helper.rb
46
+ homepage: https://github.com/oleander/acts_as_chain
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.8
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Define a set methods that should be chainable
73
+ test_files:
74
+ - spec/acts_as_chain_spec.rb
75
+ - spec/spec_helper.rb