waz-storage 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/waz-storage.rb CHANGED
@@ -3,3 +3,14 @@ require 'waz/storage/base'
3
3
  require 'waz/storage/core_service'
4
4
  require 'waz/storage/exceptions'
5
5
  require 'waz/storage/version'
6
+
7
+ # It will depende on which version of Ruby (or if you have Rails)
8
+ # but this method is required so we will add it the String class.
9
+ unless String.method_defined? :start_with?
10
+ class String
11
+ def starts_with?(prefix)
12
+ prefix = prefix.to_s
13
+ self[0, prefix.length] == prefix
14
+ end
15
+ end
16
+ end
@@ -30,8 +30,9 @@ module WAZ
30
30
  # service that wraps the calls the Windows Azure Blobs API. It's initialized with the values
31
31
  # from the default_connection on WAZ::Storage::Base initialized thru establish_connection!
32
32
  def service_instance
33
- @service_instance ||= Service.new(WAZ::Storage::Base.default_connection.merge(:type_of_service => "blob"))
34
- end
33
+ options = WAZ::Storage::Base.default_connection.merge(:type_of_service => "blob")
34
+ (@service_instances ||= {})[:account_name] ||= Service.new(options)
35
+ end
35
36
  end
36
37
 
37
38
  attr_accessor :name, :url, :content_type
@@ -64,7 +64,8 @@ module WAZ
64
64
  # service that wraps the calls the Windows Azure Blobs API. It's initialized with the values
65
65
  # from the default_connection on WAZ::Storage::Base initialized thru establish_connection!
66
66
  def service_instance
67
- @service_instance ||= Service.new(WAZ::Storage::Base.default_connection.merge(:type_of_service => "blob"))
67
+ options = WAZ::Storage::Base.default_connection.merge(:type_of_service => "blob")
68
+ (@service_instances ||= {})[:account_name] ||= Service.new(options)
68
69
  end
69
70
  end
70
71
 
@@ -28,7 +28,8 @@ module WAZ
28
28
  # service that wraps the calls the Windows Azure Queues API. It's initialized with the values
29
29
  # from the default_connection on WAZ::Storage::Base initialized thru establish_connection!
30
30
  def service_instance
31
- @service_instance ||= Service.new(WAZ::Storage::Base.default_connection.merge(:type_of_service => 'queue'))
31
+ options = WAZ::Storage::Base.default_connection.merge(:type_of_service => "queue")
32
+ (@service_instances ||= {})[:account_name] ||= Service.new(options)
32
33
  end
33
34
  end
34
35
 
@@ -71,7 +71,8 @@ module WAZ
71
71
  # service that wraps the calls the Windows Azure Queues API. It's initialized with the values
72
72
  # from the default_connection on WAZ::Storage::Base initialized thru establish_connection!
73
73
  def service_instance
74
- @service_instance ||= Service.new(WAZ::Storage::Base.default_connection.merge(:type_of_service => 'queue'))
74
+ options = WAZ::Storage::Base.default_connection.merge(:type_of_service => "queue")
75
+ (@service_instances ||= {})[:account_name] ||= Service.new(options)
75
76
  end
76
77
  end
77
78
 
@@ -18,19 +18,49 @@ module WAZ
18
18
  raise InvalidOption, :account_name unless options.keys.include? :account_name
19
19
  raise InvalidOption, :access_key unless options.keys.include? :access_key
20
20
  options[:use_ssl] = false unless options.keys.include? :use_ssl
21
- @connection = options
21
+ (@connections ||= []) << options
22
+ end
23
+
24
+ # Block Syntax
25
+ #
26
+ # Pushes the named repository onto the context-stack,
27
+ # yields a new session, and pops the context-stack.
28
+ #
29
+ # This helps you set contextual operations like in the following sample
30
+ #
31
+ # Base.establish_connection(options) do
32
+ # # do some operations on the given context
33
+ # end
34
+ #
35
+ # The context is restored to the previous one (what you configured on establish_connection!)
36
+ # or nil.
37
+ #
38
+ # Non-Block Syntax
39
+ #
40
+ # Behaves exactly as establish_connection!
41
+ def establish_connection(options = {}) # :yields: current_context
42
+ establish_connection!(options)
43
+ if (block_given?)
44
+ begin
45
+ return yield
46
+ ensure
47
+ @connections.pop() if connected?
48
+ end
49
+ end
22
50
  end
23
51
 
24
52
  # Returns the default connection (last set) parameters. It will raise an exception WAZ::Storage::NotConnected
25
53
  # when there's no connection information registered.
26
54
  def default_connection
27
55
  raise NotConnected unless connected?
28
- return @connection
56
+ return @connections.last
29
57
  end
30
58
 
31
59
  # Returns a value indicating whether the current connection information has been set or not.
32
60
  def connected?
33
- return !@connection.nil?
61
+ return false if (@connections.nil?)
62
+ return false if (@connections.empty?)
63
+ return true
34
64
  end
35
65
  end
36
66
  end
@@ -3,7 +3,7 @@ module WAZ
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = '0'
5
5
  MINOR = '5'
6
- TINY = '2'
6
+ TINY = '3'
7
7
  end
8
8
 
9
9
  Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY].compact * '.'
data/rakefile CHANGED
@@ -8,7 +8,6 @@ require 'lib/waz-storage'
8
8
 
9
9
  namespace :test do
10
10
  Spec::Rake::SpecTask.new('run_with_rcov') do |t|
11
- puts "running tests and code coverage"
12
11
  t.spec_files = FileList['tests/waz/queues/*.rb', 'tests/waz/blobs/*.rb', 'tests/waz/storage/*.rb']
13
12
  t.rcov = true
14
13
  t.rcov_opts = ['--text-report', '--exclude', "exclude.*/.gem,test,Library,#{ENV['GEM_HOME']}", '--sort', 'coverage' ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waz-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnny G. Halife
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-15 00:00:00 -03:00
12
+ date: 2009-10-17 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency