waz-sync 0.0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.gitignore +24 -0
  2. data/LICENCE +19 -0
  3. data/README.rdoc +52 -0
  4. data/lib/waz_sync.rb +30 -0
  5. data/rakefile +4 -0
  6. data/waz-sync.gemspec +15 -0
  7. metadata +68 -0
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ config.ru
3
+ *.pid
4
+ *.log
5
+ /log/*
6
+ *.sql
7
+ *.sql.gz
8
+ ._*
9
+ config.ru
10
+ index/*
11
+ public/system/*.flv
12
+ *.DS_Store
13
+ .DS_Store
14
+ .DS_Store?
15
+ public/data_db/*.jpg
16
+ public/data_db/*.png
17
+ public/data_db/packvideo/*.zip
18
+ *.cache
19
+ public/system
20
+ public/system/*
21
+ db/sphinx/*
22
+ .bundle\n
23
+ public/stylesheets/cache/*
24
+ /tmp/*
data/LICENCE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Guillaume M.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ = Windows Azure Sync library — Simple gem for syncing assets to Windows Azure CDN
2
+ A simple client library aim to sync assets to Windows Azure, using a modified version of the great waz-storage gem
3
+
4
+ === Install
5
+ Add to your gemfile :
6
+
7
+ gem 'waz-storage', :git=>"https://github.com/gmontard/waz-storage.git"
8
+ gem 'waz-sync'
9
+
10
+ Create a config file to /app/config/azure.yml to hold your Azure credentials
11
+
12
+ development:
13
+ account_name: NAME
14
+ access_key: KEY
15
+
16
+ staging:
17
+ account_name: NAME
18
+ access_key: KEY
19
+
20
+ production:
21
+ account_name: NAME
22
+ access_key: KEY
23
+
24
+ === Usage
25
+ azure = WazSync.new()
26
+ ["images", "javascripts", "stylesheets"].each{|folder|
27
+ container = azure.find_or_create_container(folder)
28
+ Dir.glob("#{Rails.root.to_s}/public/#{folder}/**/*").each do |file|
29
+ if File.file?(file)
30
+ filename = file.gsub("/public/#{folder}/", "").gsub("#{Rails.root.to_s}", "")
31
+ azure.send_or_update(container, file, filename)
32
+ end
33
+ end
34
+ }
35
+
36
+ This simple code will sync all your assets unders "images", "javascripts" and "stylesheets" to Windows Azure CDN
37
+
38
+ === Remarks
39
+ This Gem use a modified version of the waz-storage gem that you can find there : https://github.com/johnnyhalife/waz-storage
40
+
41
+ You can find my modified version here : https://github.com/gmontard/waz-storage
42
+
43
+ === TODO's
44
+ Tests !!!!
45
+
46
+ === Meta
47
+
48
+ Written by Guillaume Montard
49
+
50
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
51
+
52
+ http://github.com/gmontard/waz-sync
data/lib/waz_sync.rb ADDED
@@ -0,0 +1,30 @@
1
+ class WazSync
2
+
3
+ require 'waz-blobs'
4
+
5
+ def initialize
6
+ yaml_azure = YAML::load(ERB.new(File.read(Rails.root.to_s + '/config/azure.yml')).result).stringify_keys[Rails.env]
7
+ WAZ::Storage::Base.establish_connection!(:account_name => yaml_azure["account_name"], :access_key => yaml_azure["access_key"])
8
+ end
9
+
10
+ def find_or_create_container(container)
11
+ if WAZ::Blobs::Container.find(container).nil?
12
+ container = WAZ::Blobs::Container.create(container)
13
+ container.public_access = "blob"
14
+ else
15
+ container = WAZ::Blobs::Container.find(container)
16
+ end
17
+ return(container)
18
+ end
19
+
20
+ def send_or_update(container, file, filename)
21
+ obj = container[filename] rescue nil
22
+
23
+ if !obj || (obj.railsetag != Digest::MD5.hexdigest(File.read(file)))
24
+ logger.info("Create / Updating : #{filename}")
25
+ content_type = MIME::Types.type_for(file).to_s.blank? ? "text/plain" : MIME::Types.type_for(file).to_s
26
+ container.store(filename, File.read(file), content_type) rescue 'error'
27
+ end
28
+ end
29
+
30
+ end
data/rakefile ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
3
+ require 'rake/rdoctask'
4
+ require 'bundler/gem_tasks'
data/waz-sync.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.name = 'waz-sync'
4
+ gem.version = '0.0.2.2'
5
+ gem.date = '2012-04-20'
6
+ gem.description = %q{A simple client library aim to sync assets to Windows Azure CDN, using a modified version of the great waz-storage gem}
7
+ gem.summary = %q{Client library for Syncing assets to Windows Azure CDN}
8
+ gem.license = 'MIT'
9
+ gem.authors = ["Guillaume MONTARD"]
10
+ gem.email = 'montard@gmail.com'
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.homepage = 'https://github.com/gmontard/waz-sync'
13
+ gem.require_paths = ["lib"]
14
+ gem.rubyforge_project = 'waz-sync'
15
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: waz-sync
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ - 2
10
+ version: 0.0.2.2
11
+ platform: ruby
12
+ authors:
13
+ - Guillaume MONTARD
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-20 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A simple client library aim to sync assets to Windows Azure CDN, using a modified version of the great waz-storage gem
23
+ email: montard@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - LICENCE
33
+ - README.rdoc
34
+ - lib/waz_sync.rb
35
+ - rakefile
36
+ - waz-sync.gemspec
37
+ has_rdoc: true
38
+ homepage: https://github.com/gmontard/waz-sync
39
+ licenses:
40
+ - MIT
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project: waz-sync
63
+ rubygems_version: 1.3.6
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Client library for Syncing assets to Windows Azure CDN
67
+ test_files: []
68
+