dragonfly-azure_data_store 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abfcf8822003391e22602bad3e8fe35278b440be
4
- data.tar.gz: 6b5e45a80be9080f92a22bd2177bb6769a214c5b
3
+ metadata.gz: 4d2024967b29c0e312ad70474d518ceb9b6ac941
4
+ data.tar.gz: 69f109e7bee50858b5cd899255b5bc660c1f4f9d
5
5
  SHA512:
6
- metadata.gz: 9164c7b3b89ca5582f01ac9241e45ab6fc1f33a28c40cc4298b1b38edb75fa1d9ea9264a5c6fd466a759ec66b40206a3446cd563cee1b1e87dcd9e78808a28f3
7
- data.tar.gz: 1d44ef7ccf90b5d9874f4450ac7fcf72cc6094f9706a733e60f28473418a152962873b8aca1bd3b3fc96d3784f5b7639f4b0e18b9b976e9ada140e7ec96c4eef
6
+ metadata.gz: 23268df03c06d76312ae8bd52a910080cbe53a3d452878d21a4c29bd237c829e4962e7feda5a7d02c65ebcf808ea6b104cb9ad21ee4565117b428d5a417fb696
7
+ data.tar.gz: 6e2c2eed209c11d5d945296bacb21da78256027295d557b920e9b2b6d773ff0da5a5a3b11314ac36fbbeaea2bdb8c6cb0aeacc2f9e72ec519a572cb630773368
data/Gemfile.lock ADDED
@@ -0,0 +1,104 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dragonfly-azure_data_store (0.0.1)
5
+ azure-storage-blob (~> 1.0)
6
+ dragonfly (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ azure-core (0.1.14)
14
+ faraday (~> 0.9)
15
+ faraday_middleware (~> 0.10)
16
+ nokogiri (~> 1.6)
17
+ azure-storage-blob (1.0.1)
18
+ azure-core (~> 0.1.13)
19
+ azure-storage-common (~> 1.0)
20
+ nokogiri (~> 1.6, >= 1.6.8)
21
+ azure-storage-common (1.0.1)
22
+ azure-core (~> 0.1.13)
23
+ nokogiri (~> 1.6, >= 1.6.8)
24
+ byebug (10.0.0)
25
+ coderay (1.1.2)
26
+ diff-lcs (1.3)
27
+ dragonfly (1.1.4)
28
+ addressable (~> 2.3)
29
+ multi_json (~> 1.0)
30
+ rack (>= 1.3)
31
+ faraday (0.14.0)
32
+ multipart-post (>= 1.2, < 3)
33
+ faraday_middleware (0.12.2)
34
+ faraday (>= 0.7.4, < 1.0)
35
+ ffi (1.9.21)
36
+ formatador (0.2.5)
37
+ guard (2.14.2)
38
+ formatador (>= 0.2.4)
39
+ listen (>= 2.7, < 4.0)
40
+ lumberjack (>= 1.0.12, < 2.0)
41
+ nenv (~> 0.1)
42
+ notiffany (~> 0.0)
43
+ pry (>= 0.9.12)
44
+ shellany (~> 0.0)
45
+ thor (>= 0.18.1)
46
+ guard-compat (1.2.1)
47
+ guard-rspec (4.7.3)
48
+ guard (~> 2.1)
49
+ guard-compat (~> 1.1)
50
+ rspec (>= 2.99.0, < 4.0)
51
+ listen (3.1.5)
52
+ rb-fsevent (~> 0.9, >= 0.9.4)
53
+ rb-inotify (~> 0.9, >= 0.9.7)
54
+ ruby_dep (~> 1.2)
55
+ lumberjack (1.0.12)
56
+ method_source (0.9.0)
57
+ mini_portile2 (2.3.0)
58
+ multi_json (1.13.1)
59
+ multipart-post (2.0.0)
60
+ nenv (0.3.0)
61
+ nokogiri (1.8.2)
62
+ mini_portile2 (~> 2.3.0)
63
+ notiffany (0.1.1)
64
+ nenv (~> 0.1)
65
+ shellany (~> 0.0)
66
+ pry (0.11.3)
67
+ coderay (~> 1.1.0)
68
+ method_source (~> 0.9.0)
69
+ pry-byebug (3.6.0)
70
+ byebug (~> 10.0)
71
+ pry (~> 0.10)
72
+ public_suffix (3.0.1)
73
+ rack (2.0.4)
74
+ rb-fsevent (0.10.2)
75
+ rb-inotify (0.9.10)
76
+ ffi (>= 0.5.0, < 2)
77
+ rspec (3.7.0)
78
+ rspec-core (~> 3.7.0)
79
+ rspec-expectations (~> 3.7.0)
80
+ rspec-mocks (~> 3.7.0)
81
+ rspec-core (3.7.1)
82
+ rspec-support (~> 3.7.0)
83
+ rspec-expectations (3.7.0)
84
+ diff-lcs (>= 1.2.0, < 2.0)
85
+ rspec-support (~> 3.7.0)
86
+ rspec-mocks (3.7.0)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.7.0)
89
+ rspec-support (3.7.0)
90
+ ruby_dep (1.5.0)
91
+ shellany (0.0.1)
92
+ thor (0.20.0)
93
+
94
+ PLATFORMS
95
+ ruby
96
+
97
+ DEPENDENCIES
98
+ dragonfly-azure_data_store!
99
+ guard-rspec
100
+ pry-byebug
101
+ rspec (~> 3.0)
102
+
103
+ BUNDLED WITH
104
+ 1.16.1
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/README.md CHANGED
@@ -1,43 +1,84 @@
1
1
  # Dragonfly::AzureDataStore
2
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/dragonfly/azure_data_store`. 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
3
+ Microsoft Azure data store for use with the
4
+ [Dragonfly](http://github.com/markevans/dragonfly) gem.
6
5
 
7
6
  ## Installation
8
7
 
9
- Add this line to your application's Gemfile:
10
-
11
8
  ```ruby
12
9
  gem 'dragonfly-azure_data_store'
13
10
  ```
14
11
 
15
- And then execute:
12
+ ## Usage
13
+
14
+ Configuration (remember the require)
16
15
 
17
- $ bundle
16
+ ```ruby
17
+ require 'dragonfly/azure_data_store'
18
18
 
19
- Or install it yourself as:
19
+ Dragonfly.app.configure do
20
+ # ...
20
21
 
21
- $ gem install dragonfly-azure_data_store
22
+ datastore :azure, account_name: ENV['AZURE_ACCOUNT_NAME'],
23
+ container_name: ENV['AZURE_CONTAINER_NAME'],
24
+ access_key: ENV['AZURE_ACCESS_KEY']
22
25
 
23
- ## Usage
26
+ # ...
27
+ end
28
+ ```
29
+
30
+ ### Available configuration options
31
+
32
+ ```ruby
33
+ :account_name
34
+ :container_name
35
+ :access_key
36
+ :url_scheme # defaults to "http"
37
+ :url_host # defaults to "<account_name>.blob.core.windows.net"
38
+ :root_path # store all content under a subdirectory - uids will be relative to this - defaults to nil
39
+ ```
40
+
41
+ ### Serving directly from Azure
24
42
 
25
- TODO: Write usage instructions here
43
+ You can get the Azure url using
26
44
 
27
- ## Development
45
+ ```ruby
46
+ Dragonfly.app.remote_url_for('some/uid')
47
+ ```
48
+
49
+ or
50
+
51
+ ```ruby
52
+ my_model.attachment.remote_url
53
+ ```
28
54
 
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.
55
+ or with an https url:
30
56
 
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).
57
+ ```ruby
58
+ my_model.attachment.remote_url(scheme: 'https') # also configurable for all urls with 'url_scheme'
59
+ ```
60
+
61
+ or with a custom host:
62
+
63
+ ```ruby
64
+ my_model.attachment.remote_url(host: 'custom.domain') # also configurable for all urls with 'url_host'
65
+ ```
32
66
 
33
67
  ## Contributing
34
68
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dragonfly-azure_data_store. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
69
+ Bug reports and pull requests are welcome on GitHub at
70
+ https://github.com/meloncargo/dragonfly-azure_data_store. This project is
71
+ intended to be a safe, welcoming space for collaboration, and contributors are
72
+ expected to adhere to the [Contributor Covenant](http://contributor-covenant.org)
73
+ code of conduct.
36
74
 
37
75
  ## License
38
76
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
77
+ The gem is available as open source under the terms of the
78
+ [MIT License](https://opensource.org/licenses/MIT).
40
79
 
41
80
  ## Code of Conduct
42
81
 
43
- Everyone interacting in the Dragonfly::AzureDataStore project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dragonfly-azure_data_store/blob/master/CODE_OF_CONDUCT.md).
82
+ Everyone interacting in the Dragonfly::AzureDataStore project’s codebases, issue
83
+ trackers, chat rooms and mailing lists is expected to follow the
84
+ [code of conduct](https://github.com/meloncargo/dragonfly-azure_data_store/blob/master/CODE_OF_CONDUCT.md).
@@ -23,5 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_runtime_dependency 'azure-storage-blob', '~> 1.0'
25
25
  spec.add_runtime_dependency 'dragonfly', '~> 1.0'
26
+ spec.add_development_dependency 'guard-rspec', '~> 4.0'
27
+ spec.add_development_dependency 'pry-byebug', '~> 3.0'
26
28
  spec.add_development_dependency 'rspec', '~> 3.0'
27
29
  end
@@ -1,5 +1,5 @@
1
1
  module Dragonfly
2
2
  class AzureDataStore
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -1,37 +1,56 @@
1
+ require 'dragonfly'
1
2
  require 'azure/storage/blob'
2
3
 
3
4
  Dragonfly::App.register_datastore(:azure) { Dragonfly::AzureDataStore }
4
5
 
5
6
  module Dragonfly
6
7
  class AzureDataStore
7
- attr_accessor :account_name, :access_key, :container_name, :root_path
8
+ attr_accessor :account_name, :access_key, :container_name, :root_path,
9
+ :url_scheme, :url_host
8
10
 
9
11
  def initialize(opts = {})
10
12
  @account_name = opts[:account_name]
11
13
  @access_key = opts[:access_key]
12
14
  @container_name = opts[:container_name]
13
15
  @root_path = opts[:root_path]
16
+ @url_scheme = opts[:url_scheme] || 'http'
17
+ @url_host = opts[:url_host]
14
18
  end
15
19
 
16
- def write(content, opts = {})
20
+ def write(content, _opts = {})
17
21
  blob = nil
18
22
  filename = path_for(content.name || 'file')
19
23
  content.file do |f|
20
- blob = azure_blob_service.create_block_blob(
24
+ blob = storage.create_block_blob(
21
25
  container.name, full_path(filename), f
22
26
  )
23
- # storage.put_object(bucket_name, full_path(uid), f, full_storage_headers(headers, content.meta))
24
27
  end
25
- # content = File.open("test.png", "rb") { |file| file.read }
26
28
  filename
27
29
  end
28
30
 
29
31
  def read(uid)
32
+ blob = storage.get_blob(container.name, full_path(uid))
33
+ [blob[1], blob[0].properties]
34
+ rescue Azure::Core::Http::HTTPError
35
+ nil
30
36
  end
31
37
 
32
38
  def destroy(uid)
39
+ storage.delete_blob(container.name, full_path(uid))
40
+ true
41
+ rescue Azure::Core::Http::HTTPError
42
+ false
33
43
  end
34
44
 
45
+ def url_for(uid, opts = {})
46
+ scheme = opts[:scheme] || url_scheme
47
+ host = opts[:host] || url_host ||
48
+ "#{account_name}.blob.core.windows.net"
49
+ "#{scheme}://#{host}/#{container_name}/#{full_path(uid)}"
50
+ end
51
+
52
+ private
53
+
35
54
  def storage
36
55
  @storage ||=
37
56
  Azure::Storage::Blob::BlobService.create(
@@ -49,13 +68,9 @@ module Dragonfly
49
68
  end
50
69
  end
51
70
 
52
- # def generate_uid(name)
53
- # "#{Time.now.strftime '%Y/%m/%d/%H/%M/%S'}/#{SecureRandom.uuid}/#{name}"
54
- # end
55
-
56
71
  def path_for(filename)
57
72
  time = Time.now
58
- "#{time.strftime '%Y/%m/%d/'}#{rand(1e15).to_s(36)}_#{filename.gsub(/[^\w.]+/,'_')}"
73
+ "#{time.strftime '%Y/%m/%d/'}#{rand(1e15).to_s(36)}_#{filename.gsub(/[^\w.]+/, '_')}"
59
74
  end
60
75
 
61
76
  def full_path(filename)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly-azure_data_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alter Lagos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-10 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: azure-storage-blob
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
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'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +92,8 @@ files:
64
92
  - ".travis.yml"
65
93
  - CODE_OF_CONDUCT.md
66
94
  - Gemfile
95
+ - Gemfile.lock
96
+ - Guardfile
67
97
  - LICENSE.txt
68
98
  - README.md
69
99
  - Rakefile