vault-tools 0.0.7 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/vault-tools.rb +1 -0
- data/lib/vault-tools/hid.rb +6 -5
- data/lib/vault-tools/pipeline.rb +35 -0
- data/lib/vault-tools/version.rb +1 -1
- data/test/pipeline_test.rb +67 -0
- data/vault-tools.gemspec +1 -2
- metadata +8 -5
data/lib/vault-tools.rb
CHANGED
data/lib/vault-tools/hid.rb
CHANGED
@@ -7,14 +7,15 @@ module Vault
|
|
7
7
|
# @param heroku_id [String] A Heroku app ID over user ID
|
8
8
|
# @raise [ArgumentError] Raised if a malformed Heroku ID is provided.
|
9
9
|
# @return [String] A v5 UUID that uniquely represents the app.
|
10
|
-
def self.hid_to_uuid(
|
11
|
-
case
|
10
|
+
def self.hid_to_uuid(heroku_id)
|
11
|
+
case heroku_id
|
12
12
|
when /^user/
|
13
|
-
User.hid_to_uuid(
|
13
|
+
User.hid_to_uuid(heroku_id)
|
14
14
|
when /^app/
|
15
|
-
App.hid_to_uuid(
|
15
|
+
App.hid_to_uuid(heroku_id)
|
16
16
|
else
|
17
|
-
raise ArgumentError, "#{
|
17
|
+
raise ArgumentError, "#{heroku_id} is not a valid Heroku app or " +
|
18
|
+
"user ID."
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Vault
|
2
|
+
# Pipes and Filters implementations
|
3
|
+
#
|
4
|
+
# Individual filters do work with ::call(object)
|
5
|
+
#
|
6
|
+
# Compose a Pipeline with the ::use method
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# Pricer = Class.new(Pipeline)
|
11
|
+
#
|
12
|
+
# class AppTierPricer < Pricer
|
13
|
+
# use PlanScoper, Quantizer, AppGrouper
|
14
|
+
# use UserGrouper
|
15
|
+
# end
|
16
|
+
class Pipeline
|
17
|
+
def self.use(*args)
|
18
|
+
@filters ||= []
|
19
|
+
@filters.push *args
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.filters
|
23
|
+
@filters
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.process(thing)
|
27
|
+
return thing unless filters
|
28
|
+
filters.each do |filter|
|
29
|
+
thing = filter.call(thing)
|
30
|
+
yield thing, filter if block_given?
|
31
|
+
end
|
32
|
+
thing
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/vault-tools/version.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class PipelineTest < Vault::TestCase
|
4
|
+
include Vault
|
5
|
+
|
6
|
+
# create a Module, Class, and lambda
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@append_a = Module.new
|
10
|
+
@append_a.define_singleton_method(:call) do |thing|
|
11
|
+
thing << 'a'
|
12
|
+
thing
|
13
|
+
end
|
14
|
+
|
15
|
+
@append_b = Class.new
|
16
|
+
@append_b.define_singleton_method(:call) do |thing|
|
17
|
+
thing << 'b'
|
18
|
+
thing
|
19
|
+
end
|
20
|
+
|
21
|
+
@append_c = lambda do |thing|
|
22
|
+
thing << 'c'
|
23
|
+
thing
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# No shirt, no shoes, no problem
|
28
|
+
def test_noops_with_no_composites
|
29
|
+
pipeline = Class.new(Pipeline)
|
30
|
+
result = pipeline.process([])
|
31
|
+
assert_equal([], result)
|
32
|
+
end
|
33
|
+
|
34
|
+
# #filters returns the filters
|
35
|
+
def test_filters_accessor
|
36
|
+
pipeline = Class.new(Pipeline)
|
37
|
+
pipeline.use @append_a, @append_b
|
38
|
+
assert_equal([@append_a, @append_b], pipeline.filters)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Single call to ::use
|
42
|
+
def test_with_one_composite
|
43
|
+
pipeline = Class.new(Pipeline)
|
44
|
+
pipeline.use @append_a
|
45
|
+
result = pipeline.process([])
|
46
|
+
assert_equal(['a'], result)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Single call to ::use with multiple classes
|
50
|
+
# are chained in the order they are added
|
51
|
+
def test_with_multiple_composites
|
52
|
+
pipeline = Class.new(Pipeline)
|
53
|
+
pipeline.use @append_a, @append_b
|
54
|
+
result = pipeline.process([])
|
55
|
+
assert_equal(['a', 'b'], result)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Multiple calls to ::use are chained in
|
59
|
+
# the order they are added
|
60
|
+
def test_with_multiple_compositions
|
61
|
+
pipeline = Class.new(Pipeline)
|
62
|
+
pipeline.use @append_a, @append_b
|
63
|
+
pipeline.use @append_c
|
64
|
+
result = pipeline.process([])
|
65
|
+
assert_equal(['a', 'b', 'c'], result)
|
66
|
+
end
|
67
|
+
end
|
data/vault-tools.gemspec
CHANGED
@@ -8,8 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.name = "vault-tools"
|
9
9
|
gem.version = Vault::Tools::VERSION
|
10
10
|
gem.authors = ["Chris Continanza", "Jamu Kakar"]
|
11
|
-
gem.email = ["
|
12
|
-
"jkakar@heroku.com"]
|
11
|
+
gem.email = ["christopher.continanza@gmail.com", "csquared@heroku.com","jkakar@heroku.com","jkakar@kakar.ca"]
|
13
12
|
gem.description = "Basic tools for Heroku Vault's Ruby projects"
|
14
13
|
gem.summary = "Test classes, base web classes, and helpers - oh my!"
|
15
14
|
gem.homepage = ""
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: scrolls
|
@@ -62,9 +62,10 @@ dependencies:
|
|
62
62
|
version: '0'
|
63
63
|
description: Basic tools for Heroku Vault's Ruby projects
|
64
64
|
email:
|
65
|
-
-
|
65
|
+
- christopher.continanza@gmail.com
|
66
66
|
- csquared@heroku.com
|
67
67
|
- jkakar@heroku.com
|
68
|
+
- jkakar@kakar.ca
|
68
69
|
executables: []
|
69
70
|
extensions: []
|
70
71
|
extra_rdoc_files: []
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- lib/vault-tools/config.rb
|
89
90
|
- lib/vault-tools/hid.rb
|
90
91
|
- lib/vault-tools/log.rb
|
92
|
+
- lib/vault-tools/pipeline.rb
|
91
93
|
- lib/vault-tools/product.rb
|
92
94
|
- lib/vault-tools/sinatra_helpers/html_serializer.rb
|
93
95
|
- lib/vault-tools/user.rb
|
@@ -97,6 +99,7 @@ files:
|
|
97
99
|
- test/config_test.rb
|
98
100
|
- test/helper.rb
|
99
101
|
- test/hid_test.rb
|
102
|
+
- test/pipeline_test.rb
|
100
103
|
- test/product_test.rb
|
101
104
|
- test/test_spec.rb
|
102
105
|
- test/user_test.rb
|
@@ -115,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
118
|
version: '0'
|
116
119
|
segments:
|
117
120
|
- 0
|
118
|
-
hash:
|
121
|
+
hash: -2764314088517499753
|
119
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
123
|
none: false
|
121
124
|
requirements:
|
@@ -124,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
127
|
version: '0'
|
125
128
|
segments:
|
126
129
|
- 0
|
127
|
-
hash:
|
130
|
+
hash: -2764314088517499753
|
128
131
|
requirements: []
|
129
132
|
rubyforge_project:
|
130
133
|
rubygems_version: 1.8.23
|