hoops 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f1ccb54fd9d448082cc5029ccb138ccdaf5d564
4
+ data.tar.gz: 99a701a0d9e65b059e5e5e70ca4e4a35fa8a95a5
5
+ SHA512:
6
+ metadata.gz: 6ba92fafd692e25f5be274ba8c01796eec8f81d55d655578e663d1a061f6665cd58c5850e263c32c1d18ffe24a2c9c4a7e89cb0ce637c26dc5336013ec2924ea
7
+ data.tar.gz: 69c5e2d1ebd43537b7d9d6d5f6937c15e59200414b6f0140895a0c485a6ef9e18c9c07d4bf84cb19d9b55ebbf398a70abc50510d3cd04dd0d3589497e2d772f6
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hoops.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # Feel free to open issues for suggestions and improvements
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Justin Scott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Hoops
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hoops`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hoops'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hoops
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hoops.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hoops"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/hoops.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "hoops/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hoops"
8
+ spec.version = Hoops::VERSION
9
+ spec.authors = ["Justin Scott"]
10
+ spec.email = ["jscott7561@gmail.com"]
11
+
12
+ spec.summary = "Handy Operation Oriented Programming Stuff"
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/dr0verride/hoops"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "wisper", "~> 2.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency 'wisper-rspec', '~> 0.0'
30
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
31
+ end
@@ -0,0 +1,21 @@
1
+
2
+ module Hoops
3
+ class Operation
4
+ class Lock
5
+ def initialize(signal)
6
+ @signal = signal
7
+ end
8
+
9
+ def allow?(other)
10
+ raise Operation::SignalError, <<-ERROR.strip if other != signal
11
+ Operation result already locked to #{signal}. Cannot broadcast #{other}.
12
+ ERROR
13
+
14
+ true
15
+ end
16
+
17
+ private
18
+ attr_reader :signal
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,93 @@
1
+ require "wisper"
2
+
3
+ module Hoops
4
+ class Operation
5
+ include Wisper::Publisher
6
+
7
+ SignalError = Class.new(RuntimeError)
8
+
9
+ def self.call(*args)
10
+ operation = new(*args)
11
+ yield operation if block_given?
12
+ operation.call
13
+ end
14
+
15
+ singleton_class.send(:alias_method, :[], :call)
16
+
17
+ def on_success(*args, &block)
18
+ on(success_code, &block)
19
+ end
20
+
21
+ def self.success_code
22
+ @success_code ||= if name.nil? || name == ''
23
+ :success
24
+ else
25
+ code = name.
26
+ gsub(/(.)([A-Z](?=[a-z]))/,'\1_\2').
27
+ gsub('::','').
28
+ downcase
29
+
30
+ "#{code}_success".to_sym
31
+ end
32
+ end
33
+
34
+ def self.success_code=(code)
35
+ @success_code = code
36
+ end
37
+
38
+ private
39
+
40
+ def success_code
41
+ self.class.success_code
42
+ end
43
+
44
+ def success!(*args)
45
+ lock!(:success)
46
+ broadcast(success_code, *args)
47
+ true
48
+ end
49
+
50
+ def failure!(code, *args)
51
+ lock!(:failure)
52
+ broadcast(code, *args)
53
+ false
54
+ end
55
+
56
+ def signal!(code, *args)
57
+ check_lock(:success)
58
+ broadcast(code, *args)
59
+ true
60
+ end
61
+
62
+ def lock!(signal)
63
+ @lock ||= Lock.new(signal)
64
+ check_lock(signal)
65
+ end
66
+
67
+ def check_lock(signal)
68
+ @lock.nil? || @lock.allow?(signal)
69
+ end
70
+
71
+ def forward_failure(other_operation, *ev_codes, as: nil)
72
+ forward(:failure!, other_operation, *ev_codes, as: as)
73
+ end
74
+
75
+ def forward_failure(other_operation, *ev_codes, as: nil)
76
+ forward(:success!, other_operation, *ev_codes, as: as)
77
+ end
78
+
79
+ def forward_signal(other_operation, *ev_codes, as: nil)
80
+ forward(:signal!, other_operation, *ev_codes, as: as)
81
+ end
82
+
83
+ def forward(method, other_operation, *ev_codes, as: nil)
84
+ ev_codes.each do |code|
85
+ other_operation.on(code) do |*args|
86
+ send(method, as ? as : code, *args)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ require 'hoops/operation/lock'
@@ -0,0 +1,3 @@
1
+ module Hoops
2
+ VERSION = "0.1.0"
3
+ end
data/lib/hoops.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "hoops/version"
2
+ require "hoops/operation"
3
+
4
+ module Hoops
5
+ # Your code goes here...
6
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Scott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wisper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: wisper-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.7'
97
+ description: Handy Operation Oriented Programming Stuff
98
+ email:
99
+ - jscott7561@gmail.com
100
+ executables:
101
+ - console
102
+ - setup
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Guardfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - hoops.gemspec
117
+ - lib/hoops.rb
118
+ - lib/hoops/operation.rb
119
+ - lib/hoops/operation/lock.rb
120
+ - lib/hoops/version.rb
121
+ homepage: https://github.com/dr0verride/hoops
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.11
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Handy Operation Oriented Programming Stuff
145
+ test_files: []