yogo-operation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ .bundle
21
+ .yardoc
22
+
23
+ ## PROJECT::SPECIFIC
24
+ spec/tmp
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'dataflow'
4
+ gem 'yogo-support', "~> 0.1.0"
5
+
6
+ group :development do
7
+ gem "rake"
8
+ gem "jeweler"
9
+ gem "rspec"
10
+ gem "cucumber"
11
+ gem "yard"
12
+ gem "ruby-debug"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (2.1.2)
5
+ columnize (0.3.1)
6
+ cucumber (0.8.5)
7
+ builder (~> 2.1.2)
8
+ diff-lcs (~> 1.1.2)
9
+ gherkin (~> 2.1.4)
10
+ json_pure (~> 1.4.3)
11
+ term-ansicolor (~> 1.0.4)
12
+ dataflow (0.3.1)
13
+ diff-lcs (1.1.2)
14
+ gemcutter (0.6.1)
15
+ gherkin (2.1.5)
16
+ trollop (~> 1.16.2)
17
+ git (1.2.5)
18
+ jeweler (1.4.0)
19
+ gemcutter (>= 0.1.0)
20
+ git (>= 1.2.5)
21
+ rubyforge (>= 2.0.0)
22
+ json_pure (1.4.6)
23
+ linecache (0.43)
24
+ rake (0.8.7)
25
+ rspec (1.3.0)
26
+ ruby-debug (0.10.3)
27
+ columnize (>= 0.1)
28
+ ruby-debug-base (~> 0.10.3.0)
29
+ ruby-debug-base (0.10.3)
30
+ linecache (>= 0.3)
31
+ rubyforge (2.0.4)
32
+ json_pure (>= 1.1.7)
33
+ term-ansicolor (1.0.5)
34
+ trollop (1.16.2)
35
+ yard (0.6.1)
36
+ yogo-support (0.1.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ cucumber
43
+ dataflow
44
+ jeweler
45
+ rake
46
+ rspec
47
+ ruby-debug
48
+ yard
49
+ yogo-support (~> 0.1.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ryan Heimbuch, Montana State University
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.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = yogo-operation
2
+
3
+ yogo-operation contains various extensions to Proc, including:
4
+
5
+ * Yogo::Operation::Restriction - Allows an operation to be restricted to a certain argument type.
6
+ * Yogo::Operation::Closed - Ensures that an operation is 'closed' over it's input/output.
7
+ * Yogo::Operation::Concurrent - Allows an operation to execute in its own thread.
8
+
9
+ The Yogo::Op class implements these modules and can be used without further modification.
10
+
11
+ == Note on Patches/Pull Requests
12
+
13
+ * Fork the project.
14
+ * Make your feature addition or bug fix.
15
+ * Add tests for it. This is important so I don't break it in a
16
+ future version unintentionally.
17
+ * Commit, do not mess with rakefile, version, or history.
18
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2010 Ryan Heimbuch, Montana State University. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'bundler'
5
+ Bundler.setup
6
+ rescue LoadError
7
+ puts "Bundler is not intalled. Install with: gem install bundler"
8
+ end
9
+
10
+ require 'rake'
11
+
12
+ begin
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ gem.name = "yogo-operation"
16
+ gem.summary = "specialization of Proc"
17
+ gem.description = "yogo-operation contains extensions to Proc to support various higher-order operations"
18
+ gem.email = "rheimbuch@gmail.com"
19
+ gem.homepage = "http://github.com/yogo/yogo-operation"
20
+ gem.authors = ["Ryan Heimbuch"]
21
+ gem.add_bundler_dependencies
22
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
23
+ end
24
+ Jeweler::GemcutterTasks.new
25
+ rescue LoadError
26
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
27
+ end
28
+
29
+ require 'spec/rake/spectask'
30
+ Spec::Rake::SpecTask.new(:spec) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.spec_files = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
36
+ spec.libs << 'lib' << 'spec'
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :spec => :check_dependencies
42
+
43
+ begin
44
+ require 'cucumber/rake/task'
45
+ Cucumber::Rake::Task.new(:features)
46
+
47
+ task :features => :check_dependencies
48
+ rescue LoadError
49
+ task :features do
50
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
51
+ end
52
+ end
53
+
54
+ task :default => :spec
55
+
56
+ begin
57
+ require 'yard'
58
+ YARD::Rake::YardocTask.new
59
+ rescue LoadError
60
+ task :yardoc do
61
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
62
+ end
63
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
File without changes
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'yogo-operation'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,17 @@
1
+ require 'yogo/support/proc'
2
+ require 'yogo/operation/base'
3
+ require 'yogo/operation/restricted'
4
+ require 'yogo/operation/closed'
5
+ require 'yogo/operation/concurrent'
6
+
7
+ module Yogo
8
+ class Op < Proc
9
+ extend Yogo::Operation::Base
10
+ extend Yogo::Operation::Restricted
11
+ extend Yogo::Operation::Closed
12
+ end # Op
13
+
14
+ class FlowOp < Op
15
+ extend Yogo::Operation::Concurrent
16
+ end
17
+ end # Yogo
@@ -0,0 +1,24 @@
1
+ require 'yogo/support/extension_module'
2
+ require 'yogo/support/proc/call'
3
+ require 'yogo/support/proc/partial'
4
+ require 'yogo/support/proc/compose'
5
+
6
+ module Yogo
7
+ module Operation
8
+ module Base
9
+ extend Yogo::ExtensionModule
10
+
11
+ instance_extensions do
12
+ extend Support::Proc::Call
13
+ extend Support::Proc::Partial
14
+ extend Support::Proc::Compose
15
+ end
16
+
17
+ class_extensions do
18
+ include Support::Proc::Call
19
+ include Support::Proc::Partial
20
+ include Support::Proc::Compose
21
+ end
22
+ end # Base
23
+ end # Operation
24
+ end # Yogo
@@ -0,0 +1,18 @@
1
+ require 'yogo/support/extension_module'
2
+ require 'yogo/operation/closed/call'
3
+
4
+ module Yogo
5
+ module Operation
6
+ module Closed
7
+ extend Yogo::ExtensionModule
8
+
9
+ instance_extensions do
10
+ extend Closed::Call
11
+ end
12
+
13
+ class_extensions do
14
+ include Closed::Call
15
+ end
16
+ end # Closed
17
+ end # Operation
18
+ end # Yogo
@@ -0,0 +1,18 @@
1
+ require 'yogo/operation/closed/error'
2
+
3
+ module Yogo
4
+ module Operation
5
+ module Closed
6
+ module Call
7
+ def call(*args)
8
+ argument = args.first
9
+ result = super(*args)
10
+ unless result.kind_of?(argument.class)
11
+ raise(OperationNotClosedError, :argument => argument, :result => result)
12
+ end
13
+ result
14
+ end
15
+ end # Call
16
+ end # Closed
17
+ end # Operation
18
+ end # Yogo
@@ -0,0 +1,16 @@
1
+ require 'yogo/operation/error'
2
+
3
+ module Yogo
4
+ module Operation
5
+ module Closed
6
+ class OperationNotClosedError < OperationError
7
+ def_delegators :information, :expected_type, :argument, :result
8
+ def initialize(options)
9
+ options[:message] ||= "The Operation is not closed! The argument and result of the operation were not of the same type."
10
+ options[:expected_type] ||= options[:argument].class
11
+ super(options)
12
+ end
13
+ end # OperationNotClosedError
14
+ end # Closed
15
+ end # Operation
16
+ end # Yogo
@@ -0,0 +1,18 @@
1
+ require 'yogo/support/extension_module'
2
+ require 'yogo/operation/concurrent/call'
3
+
4
+ module Yogo
5
+ module Operation
6
+ module Concurrent
7
+ extend Yogo::ExtensionModule
8
+
9
+ instance_extensions do
10
+ extend Concurrent::Call
11
+ end
12
+
13
+ class_extensions do
14
+ include Concurrent::Call
15
+ end
16
+ end # Concurrent
17
+ end # Operation
18
+ end # Yogo
@@ -0,0 +1,19 @@
1
+ require 'dataflow'
2
+
3
+ module Yogo
4
+ module Operation
5
+ module Concurrent
6
+ module Call
7
+ include Dataflow
8
+ def call(*args)
9
+ local do |result|
10
+ flow do
11
+ unify result, super(*args)
12
+ end
13
+ result
14
+ end
15
+ end
16
+ end # Call
17
+ end # Concurrent
18
+ end # Operation
19
+ end # Yogo
@@ -0,0 +1,23 @@
1
+ require 'ostruct'
2
+ require 'forwardable'
3
+
4
+ module Yogo
5
+ module Operation
6
+ class OperationError < StandardError
7
+ attr_reader :information
8
+
9
+ extend Forwardable
10
+ def_delegators :information, :operation, :action
11
+
12
+ def initialize(options={})
13
+ message = options.delete(:message)
14
+ @information = OpenStruct.new(options)
15
+ @information.freeze
16
+
17
+ message ? super(message) : super()
18
+ end
19
+
20
+
21
+ end # OperationError
22
+ end # Operation
23
+ end # Yogo
@@ -0,0 +1,23 @@
1
+ require 'yogo/support/extension_module'
2
+ require 'yogo/operation/restricted/construction'
3
+ require 'yogo/operation/restricted/call'
4
+ require 'yogo/operation/restricted/partial'
5
+
6
+ module Yogo
7
+ module Operation
8
+ module Restricted
9
+ extend Yogo::ExtensionModule
10
+
11
+ instance_extensions do
12
+ extend Restricted::Call
13
+ extend Restricted::Partial
14
+ end
15
+
16
+ class_extensions do
17
+ extend Restricted::Construction
18
+ include Restricted::Call
19
+ include Restricted::Partial
20
+ end
21
+ end # Restricted
22
+ end # Operation
23
+ end # Yogo
@@ -0,0 +1,20 @@
1
+ require 'yogo/operation/restricted/error'
2
+ require 'yogo/operation/restricted/expected_type'
3
+
4
+ module Yogo
5
+ module Operation
6
+ module Restricted
7
+ module Call
8
+ include ExpectedType
9
+
10
+ def call(*args)
11
+ argument = args.first
12
+ unless argument.kind_of?(expected_type)
13
+ raise(OperationRestrictionError, :argument => argument, :expected_type => expected_type)
14
+ end
15
+ super
16
+ end
17
+ end # Call
18
+ end # Closed
19
+ end # Operation
20
+ end # Yogo
@@ -0,0 +1,28 @@
1
+ require 'yogo/operation/restricted/expected_type'
2
+
3
+ module Yogo
4
+ module Operation
5
+ module Restricted
6
+ module Construction
7
+ def self.included(base)
8
+ raise "Inclusions not allowed. Use: extend(#{self.name})"
9
+ end
10
+
11
+ def extended(base)
12
+ base.class_eval {
13
+ include ExpectedType
14
+ }
15
+ base.instance_eval {
16
+ protected :new
17
+ }
18
+ end
19
+
20
+ def on(type, &block)
21
+ op = self.new(&block)
22
+ op.instance_eval{ self.expected_type = type }
23
+ op
24
+ end
25
+ end # Construction
26
+ end # Restricted
27
+ end # Operation
28
+ end # Yogo
@@ -0,0 +1,16 @@
1
+ require 'yogo/operation/error'
2
+
3
+ module Yogo
4
+ module Operation
5
+ module Restricted
6
+ class OperationRestrictionError < OperationError
7
+ def_delegators :information, :expected_type, :argument, :actual_type
8
+
9
+ def initialize(options)
10
+ options[:message] ||= "The Operation cannot be applied to an argument of this type!"
11
+ super(options)
12
+ end
13
+ end # OperationNotClosedError
14
+ end # Closed
15
+ end # Operation
16
+ end # Yogo
@@ -0,0 +1,16 @@
1
+ require 'yogo/support/proc/partial'
2
+
3
+ module Yogo
4
+ module Operation
5
+ module Restricted
6
+ module ExpectedType
7
+ protected
8
+ attr_accessor :expected_type
9
+
10
+ def expected_type
11
+ @expected_type ||= Object
12
+ end
13
+ end # Partial
14
+ end # Restricted
15
+ end # Operation
16
+ end # Yogo
@@ -0,0 +1,17 @@
1
+ require 'yogo/support/proc/partial'
2
+ require 'yogo/operation/restricted/expected_type'
3
+
4
+ module Yogo
5
+ module Operation
6
+ module Restricted
7
+ module Partial
8
+ include ExpectedType
9
+
10
+ def partial(*args)
11
+ applied = super(*args)
12
+ self.class.on(self.expected_type, &applied)
13
+ end
14
+ end # Partial
15
+ end # Restricted
16
+ end # Operation
17
+ end # Yogo
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'yogo-operation'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "YogoOperation" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yogo-operation
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Ryan Heimbuch
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-08 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: dataflow
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ prerelease: false
38
+ name: yogo-support
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 27
45
+ segments:
46
+ - 0
47
+ - 1
48
+ - 0
49
+ version: 0.1.0
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ prerelease: false
54
+ name: rake
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ type: :development
67
+ prerelease: false
68
+ name: jeweler
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirement: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ type: :development
81
+ prerelease: false
82
+ name: rspec
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirement: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ type: :development
95
+ prerelease: false
96
+ name: cucumber
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirement: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ type: :development
109
+ prerelease: false
110
+ name: yard
111
+ version_requirements: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirement: *id007
121
+ - !ruby/object:Gem::Dependency
122
+ type: :development
123
+ prerelease: false
124
+ name: ruby-debug
125
+ version_requirements: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirement: *id008
135
+ description: yogo-operation contains extensions to Proc to support various higher-order operations
136
+ email: rheimbuch@gmail.com
137
+ executables: []
138
+
139
+ extensions: []
140
+
141
+ extra_rdoc_files:
142
+ - LICENSE
143
+ - README.rdoc
144
+ files:
145
+ - .gitignore
146
+ - Gemfile
147
+ - Gemfile.lock
148
+ - LICENSE
149
+ - README.rdoc
150
+ - Rakefile
151
+ - VERSION
152
+ - features/step_definitions/yogo-operation_steps.rb
153
+ - features/support/env.rb
154
+ - features/yogo-operation.feature
155
+ - lib/yogo/operation.rb
156
+ - lib/yogo/operation/base.rb
157
+ - lib/yogo/operation/closed.rb
158
+ - lib/yogo/operation/closed/call.rb
159
+ - lib/yogo/operation/closed/error.rb
160
+ - lib/yogo/operation/concurrent.rb
161
+ - lib/yogo/operation/concurrent/call.rb
162
+ - lib/yogo/operation/error.rb
163
+ - lib/yogo/operation/restricted.rb
164
+ - lib/yogo/operation/restricted/call.rb
165
+ - lib/yogo/operation/restricted/construction.rb
166
+ - lib/yogo/operation/restricted/error.rb
167
+ - lib/yogo/operation/restricted/expected_type.rb
168
+ - lib/yogo/operation/restricted/partial.rb
169
+ - spec/spec.opts
170
+ - spec/spec_helper.rb
171
+ - spec/yogo-operation_spec.rb
172
+ has_rdoc: true
173
+ homepage: http://github.com/yogo/yogo-operation
174
+ licenses: []
175
+
176
+ post_install_message:
177
+ rdoc_options:
178
+ - --charset=UTF-8
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ none: false
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ hash: 3
187
+ segments:
188
+ - 0
189
+ version: "0"
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ hash: 3
196
+ segments:
197
+ - 0
198
+ version: "0"
199
+ requirements: []
200
+
201
+ rubyforge_project:
202
+ rubygems_version: 1.3.7
203
+ signing_key:
204
+ specification_version: 3
205
+ summary: specialization of Proc
206
+ test_files:
207
+ - spec/spec_helper.rb
208
+ - spec/yogo-operation_spec.rb