vault-tools 0.0.7 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/lib/vault-tools.rb CHANGED
@@ -19,3 +19,4 @@ require 'vault-tools/product'
19
19
  require 'vault-tools/sinatra_helpers/html_serializer'
20
20
  require 'vault-tools/user'
21
21
  require 'vault-tools/web'
22
+ require 'vault-tools/pipeline'
@@ -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(string)
11
- case string
10
+ def self.hid_to_uuid(heroku_id)
11
+ case heroku_id
12
12
  when /^user/
13
- User.hid_to_uuid(string)
13
+ User.hid_to_uuid(heroku_id)
14
14
  when /^app/
15
- App.hid_to_uuid(string)
15
+ App.hid_to_uuid(heroku_id)
16
16
  else
17
- raise ArgumentError, "#{string} is not a valid Heroku app or user ID."
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
@@ -1,5 +1,5 @@
1
1
  module Vault
2
2
  module Tools
3
- VERSION = "0.0.7"
3
+ VERSION = '0.0.10'
4
4
  end
5
5
  end
@@ -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 = ["chriscontinanza@gmail.com", "csquared@heroku.com",
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.7
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-01-17 00:00:00.000000000 Z
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
- - chriscontinanza@gmail.com
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: 233434446101266212
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: 233434446101266212
130
+ hash: -2764314088517499753
128
131
  requirements: []
129
132
  rubyforge_project:
130
133
  rubygems_version: 1.8.23