rainman 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,5 +7,5 @@ rvm:
7
7
  - 1.9.3
8
8
  - ree
9
9
  - rbx
10
- - rbx-2.0
10
+ - rbx-head
11
11
  - jruby
data/README.md CHANGED
@@ -40,8 +40,12 @@ module Domain
40
40
  # Register Domain.create as a public method
41
41
  define_action :create
42
42
 
43
- # Register Domain.destroy as a public method
44
- define_action :destroy
43
+ # Register Domain.destroy as a public method; Alias Domain.delete to it
44
+ define_action :destroy, :alias => :delete
45
+
46
+ # Register Domain.cancel as a public method; it delegates to a handler's
47
+ # :cancel_account method.
48
+ define_action :cancel, :delegate_to => :cancel_account
45
49
 
46
50
  # Register Domain.namservers.list as a public method
47
51
  namespace :nameservers do
@@ -69,6 +73,12 @@ class Domain::Abc
69
73
  # Returns true or false.
70
74
  def destroy(params = {})
71
75
  end
76
+
77
+ # Public: Cancel a domain account
78
+ #
79
+ # Returns true or false.
80
+ def cancel_account(params = {})
81
+ end
72
82
  end
73
83
 
74
84
  class Domain::Xyz
@@ -83,6 +93,12 @@ class Domain::Xyz
83
93
  # Returns true or false.
84
94
  def destroy(params = {})
85
95
  end
96
+
97
+ # Public: Cancel a domain account
98
+ #
99
+ # Returns true or false.
100
+ def cancel_account(params = {})
101
+ end
86
102
  end
87
103
  ```
88
104
 
@@ -149,6 +165,10 @@ Domain.create({})
149
165
 
150
166
  # Destroy a domain
151
167
  Domain.destroy({})
168
+ Domain.delete({})
169
+
170
+ # Cancel domain acconut
171
+ Domain.cancel
152
172
 
153
173
  # List domain nameservers
154
174
  Domain.nameservers.list({})
@@ -197,6 +217,9 @@ s = Service.new
197
217
  s.create
198
218
 
199
219
  s.destroy
220
+ s.delete
221
+
222
+ s.cancel
200
223
 
201
224
  s.nameservers.list
202
225
 
@@ -222,6 +245,9 @@ s = Service.new
222
245
  s.domain.create
223
246
 
224
247
  s.domain.destroy
248
+ s.domain.delete
249
+
250
+ s.domain.cancel
225
251
 
226
252
  s.domain.nameservers.list
227
253
 
@@ -20,7 +20,7 @@ module Domain
20
20
  define_action :list
21
21
  end
22
22
 
23
- define_action :list
23
+ define_action :list, :alias => :all
24
24
 
25
25
  define_action :transfer
26
26
 
@@ -171,7 +171,7 @@ module Rainman
171
171
  :class_name => "#{self.name}::#{name.to_s.camelize}"
172
172
  )
173
173
 
174
- klass = opts[:class_name].constantize
174
+ klass = opts[:class_name].to_s.constantize
175
175
 
176
176
  handlers[name] = inject_handler_methods(klass, name.to_sym)
177
177
  end
@@ -245,17 +245,26 @@ module Rainman
245
245
  # Private: Define a new action.
246
246
  #
247
247
  # name - The Symbol handler name.
248
- # opts - Options (unused currently).
248
+ # opts - A Hash of options used for creating the method:
249
+ # :delegate_to - The method name to run on the handler. Defaults
250
+ # to the action's name.
251
+ # :alias - If supplied, an alias will be created for the
252
+ # defined method.
249
253
  #
250
254
  # Example
251
255
  #
252
256
  # define_action :blah
253
257
  #
258
+ # define_action :destroy, :alias => :delete
259
+ #
254
260
  # Returns a Proc.
255
261
  def define_action(name, opts = {})
256
262
  create_method(name) do |*args, &block|
257
- current_handler_instance.runner.send(name, *args, &block)
263
+ method = opts[:delegate_to] || name
264
+ current_handler_instance.runner.send(method, *args, &block)
258
265
  end
266
+
267
+ alias_method opts[:alias], name if opts[:alias]
259
268
  end
260
269
 
261
270
  # Private: Creates a new method.
@@ -36,6 +36,26 @@ class String
36
36
  self[0].chr.downcase + camelize(self)[1..-1]
37
37
  end
38
38
  end unless respond_to?(:camelize)
39
+
40
+ # Makes an underscored, lowercase form from the expression in the string.
41
+ #
42
+ # Changes '::' to '/' to convert namespaces to paths.
43
+ #
44
+ # Examples:
45
+ # "ActiveModel".underscore # => "active_model"
46
+ # "ActiveModel::Errors".underscore # => "active_model/errors"
47
+ #
48
+ # As a rule of thumb you can think of +underscore+ as the inverse of +camelize+,
49
+ # though there are cases where that does not hold:
50
+ #
51
+ # "SSLError".underscore.camelize # => "SslError"
52
+ def underscore
53
+ gsub(/::/, '/').
54
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
55
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
56
+ tr("-", "_").
57
+ downcase
58
+ end
39
59
  end
40
60
 
41
61
  # From lib/active_support/core_ext/hash/reverse_merge.rb
@@ -1,3 +1,3 @@
1
1
  module Rainman
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
  gem.version = Rainman::VERSION
16
16
 
17
- gem.add_development_dependency 'rspec', '~> 2.7.0'
17
+ gem.add_development_dependency 'rspec', '~> 2.8.0'
18
18
  gem.add_development_dependency 'autotest-standalone', '~> 4.5.8'
19
19
  gem.add_development_dependency 'rake', '~> 0.9.2.2'
20
20
  end
@@ -19,6 +19,7 @@ describe "Rainman integration" do
19
19
 
20
20
  describe "Opensrs integration" do
21
21
  its(:list) { should == :opensrs_list }
22
+ its(:all) { should == :opensrs_list }
22
23
  its(:transfer) { should == :opensrs_transfer }
23
24
  its("nameservers.list") { should == :opensrs_ns_list }
24
25
  end
@@ -33,6 +34,7 @@ describe "Rainman integration" do
33
34
  end
34
35
 
35
36
  its(:list) { should == :enom_list }
37
+ its(:all) { should == :enom_list }
36
38
  its(:transfer) { should == :enom_transfer }
37
39
  its("nameservers.list") { should == :enom_ns_list }
38
40
  end
@@ -198,22 +198,60 @@ describe "Rainman::Driver" do
198
198
  @bob.should_receive(:extend).with(Rainman::Handler)
199
199
  @module.send(:register_handler, :bob)
200
200
  end
201
+
202
+ describe ":class_name option" do
203
+ it "allows a string" do
204
+ @module.send(:register_handler, :bob, :class_name => 'MissDaisy::Bob')
205
+ @module.handlers.should have_key(:bob)
206
+ @module.handlers[:bob].should == @bob
207
+ end
208
+
209
+ it "allows a constant" do
210
+ @module.send(:register_handler, :bob, :class_name => MissDaisy::Bob)
211
+ @module.handlers.should have_key(:bob)
212
+ @module.handlers[:bob].should == @bob
213
+ end
214
+ end
201
215
  end
202
216
 
203
217
  describe "#define_action" do
218
+ before do
219
+ @klass = Class.new do
220
+ def self.name; 'Bob'; end
221
+ def profile; :bob_is_cool; end
222
+ def self.parent_klass; end
223
+ end
224
+
225
+ @module.const_set(:Bob, @klass)
226
+
227
+ @runner = Rainman::Runner.new(MissDaisy::Bob.new)
228
+ @klass.stub(:runner).and_return(@runner)
229
+ @module.stub(:current_handler_instance).and_return(@klass)
230
+ end
231
+
204
232
  it "creates the method" do
205
233
  @module.should_not respond_to(:blah)
206
234
  @module.send(:define_action, :blah)
207
235
  @module.should respond_to(:blah)
208
-
209
- klass = Class.new.new
210
- runner = Rainman::Runner.new(klass)
211
- klass.stub(:runner).and_return(runner)
212
- @module.stub(:current_handler_instance).and_return(klass)
213
- runner.should_receive(:send).with(:blah)
236
+ @runner.should_receive(:send).with(:blah)
214
237
 
215
238
  @module.blah
216
239
  end
240
+
241
+ it "aliases the method if :alias is supplied" do
242
+ @module.should_not respond_to(:blah)
243
+ @module.send(:define_action, :blah, :alias => :superBLAH)
244
+ @module.should respond_to(:blah)
245
+ @module.should respond_to(:superBLAH)
246
+ @runner.stub(:blah).and_return(:this_is_the_blah)
247
+ @module.superBLAH.should == :this_is_the_blah
248
+ end
249
+
250
+ it "delegates the method if :delegate_to is supplied" do
251
+ @module.send(:define_action, :description, :delegate_to => :profile)
252
+ @module.should respond_to(:description)
253
+ @module.description.should == :bob_is_cool
254
+ end
217
255
  end
218
256
 
219
257
  describe "#create_method" do
@@ -14,6 +14,11 @@ describe "Rainman support" do
14
14
  "some_module/some_class".camelize.should == "SomeModule::SomeClass"
15
15
  end
16
16
 
17
+ describe "String#underscore" do
18
+ "FooBar".underscore.should == "foo_bar"
19
+ "SomeModule::SomeClass".underscore.should == "some_module/some_class"
20
+ end
21
+
17
22
  describe "Hash#reverse_merge" do
18
23
  a = { :first => :ABC, :a => :a }
19
24
  b = { :first => :XYZ, :b => :b }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,23 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000 -05:00
13
- default_executable:
12
+ date: 2012-02-03 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
- requirement: &70116374547760 !ruby/object:Gem::Requirement
16
+ requirement: &20366820 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
21
20
  - !ruby/object:Gem::Version
22
- version: 2.7.0
21
+ version: 2.8.0
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *70116374547760
24
+ version_requirements: *20366820
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: autotest-standalone
28
- requirement: &70116374547060 !ruby/object:Gem::Requirement
27
+ requirement: &20366160 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 4.5.8
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *70116374547060
35
+ version_requirements: *20366160
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: rake
39
- requirement: &70116374546260 !ruby/object:Gem::Requirement
38
+ requirement: &20365100 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
@@ -44,7 +43,7 @@ dependencies:
44
43
  version: 0.9.2.2
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *70116374546260
46
+ version_requirements: *20365100
48
47
  description: A library for writing drivers using the abstract factory pattern
49
48
  email:
50
49
  - jmazzi@gmail.com
@@ -80,7 +79,6 @@ files:
80
79
  - spec/rainman/support_spec.rb
81
80
  - spec/rainman_spec.rb
82
81
  - spec/spec_helper.rb
83
- has_rdoc: true
84
82
  homepage: http://www.eng5.com
85
83
  licenses: []
86
84
  post_install_message:
@@ -95,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
93
  version: '0'
96
94
  segments:
97
95
  - 0
98
- hash: -1604667842833133172
96
+ hash: 3481354872297427005
99
97
  required_rubygems_version: !ruby/object:Gem::Requirement
100
98
  none: false
101
99
  requirements:
@@ -104,10 +102,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
102
  version: '0'
105
103
  segments:
106
104
  - 0
107
- hash: -1604667842833133172
105
+ hash: 3481354872297427005
108
106
  requirements: []
109
107
  rubyforge_project:
110
- rubygems_version: 1.6.2
108
+ rubygems_version: 1.8.11
111
109
  signing_key:
112
110
  specification_version: 3
113
111
  summary: Rainman is an experiment in writing drivers and handlers. It is a Ruby implementation