method_object 0.0.1

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/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in method_object.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rake'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jared Grippe
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,99 @@
1
+ # MethodObject
2
+
3
+ MethodObject is a simple class for facilitating the method object pattern.
4
+
5
+ You can think of a MethodObject as a proc with private methods.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'method_object'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install method_object
20
+
21
+ ## Usage
22
+
23
+
24
+ class Car
25
+
26
+ # take the following long method
27
+ def drive_to location, speed=:slow
28
+ # find location
29
+ Lorem ipsum dolor sit amet, consectetur adipisicing
30
+ elit, sed do eiusmod tempor incididunt ut labore
31
+
32
+ # set speed
33
+ et dolore magna aliqua. Ut enim ad minim veniam,
34
+ quis nostrud exercitation ullamco laboris nisi ut
35
+ aliquip ex ea commodo
36
+
37
+ # start car
38
+ consequat. Duis aute irure dolor in reprehenderit in voluptate
39
+ cillum dolore eu fugiat nulla pariatur. Excepteur
40
+ proident, sunt in culpa qui officia deserunt mollit anim
41
+
42
+ # go
43
+ id est laborum.
44
+ end
45
+
46
+ end
47
+
48
+ Rather then complecting your Car object with more the one method that all
49
+ have to do with driving to a location you can use a method object to break
50
+ up your code without cluttering Car
51
+
52
+ class Car
53
+
54
+ class DriveTo < MethodObject
55
+ def call location, speed
56
+ @location, @speed = location, speed
57
+ find_location
58
+ set_speed
59
+ start_car
60
+ go
61
+ end
62
+
63
+ def find_location
64
+ Lorem ipsum dolor sit amet, consectetur adipisicing
65
+ elit, sed do eiusmod tempor incididunt ut labore
66
+ end
67
+
68
+ def set_speed
69
+ et dolore magna aliqua. Ut enim ad minim veniam,
70
+ quis nostrud exercitation ullamco laboris nisi ut
71
+ aliquip ex ea commodo
72
+ end
73
+
74
+ def start_car
75
+ consequat. Duis aute irure dolor in reprehenderit in voluptate
76
+ cillum dolore eu fugiat nulla pariatur. Excepteur
77
+ proident, sunt in culpa qui officia deserunt mollit anim
78
+ end
79
+
80
+ def go
81
+ id est laborum.
82
+ end
83
+
84
+
85
+ end
86
+
87
+ def drive_to location, speed=:slow
88
+ DriveTo.call(location, speed)
89
+ end
90
+
91
+ end
92
+
93
+ ## Contributing
94
+
95
+ 1. Fork it
96
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
97
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
98
+ 4. Push to the branch (`git push origin my-new-feature`)
99
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ class MethodObject
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../method_object/version', __FILE__)
2
+
3
+ class MethodObject
4
+
5
+ class << self
6
+
7
+ private :new
8
+ def call *args
9
+ new.call(*args)
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+
16
+ eval <<-RUBY if $0 == __FILE__
17
+
18
+ require 'test/unit'
19
+
20
+ # example method objects
21
+ class FindTreasureChest < MethodObject
22
+ def call *args
23
+ args + [:treasure_chest]
24
+ end
25
+ end
26
+
27
+ #tests
28
+ class MethodObjectTestUnitTestCase < Test::Unit::TestCase
29
+
30
+ def test_method_objects_have_private_new_method
31
+ assert_raises(NoMethodError){ FindTreasureChest.new }
32
+ end
33
+
34
+ def test_unknown_options
35
+ assert_equal FindTreasureChest.call, [:treasure_chest]
36
+ end
37
+
38
+ def test_that_expected_options_are_ok
39
+ assert_equal FindTreasureChest.call(:a, :size => 42), [:a, {:size => 42}, :treasure_chest]
40
+ end
41
+
42
+ end
43
+
44
+ RUBY
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/method_object/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jared Grippe"]
6
+ gem.email = ["jared@deadlyicon.com"]
7
+ gem.description = %q{wraps up the method object pattern into a class}
8
+ gem.summary = %q{wraps up the method object pattern into a class}
9
+ gem.homepage = "https://github.com/deadlyicon/method_object"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "method_object"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MethodObject::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: method_object
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jared Grippe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: wraps up the method object pattern into a class
15
+ email:
16
+ - jared@deadlyicon.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/method_object.rb
27
+ - lib/method_object/version.rb
28
+ - method_object.gemspec
29
+ homepage: https://github.com/deadlyicon/method_object
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ segments:
42
+ - 0
43
+ hash: -1718536300216077371
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ segments:
51
+ - 0
52
+ hash: -1718536300216077371
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: wraps up the method object pattern into a class
59
+ test_files: []