fog-local-0.3.0/0000755000004100000410000000000012677055751013424 5ustar www-datawww-datafog-local-0.3.0/Rakefile0000644000004100000410000000026312677055751015072 0ustar www-datawww-datarequire "bundler/gem_tasks" task :default => :test mock = ENV['FOG_MOCK'] || 'false' desc "Run tests" task :test do sh("export FOG_MOCK=#{mock} && bundle exec shindont") end fog-local-0.3.0/Gemfile0000644000004100000410000000013612677055751014717 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in fog-local.gemspec gemspec fog-local-0.3.0/tests/0000755000004100000410000000000012677055751014566 5ustar www-datawww-datafog-local-0.3.0/tests/helper.rb0000644000004100000410000000144512677055751016376 0ustar www-datawww-databegin require "codeclimate-test-reporter" CodeClimate::TestReporter.start rescue LoadError => e $stderr.puts "not recording test coverage: #{e.inspect}" end require File.expand_path('../../lib/fog/local', __FILE__) Bundler.require(:test) require 'tmpdir' Excon.defaults.merge!(:debug_request => true, :debug_response => true) require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')) # This overrides the default 600 seconds timeout during live test runs if Fog.mocking? Fog.timeout = ENV['FOG_TEST_TIMEOUT'] || 2000 Fog::Logger.warning "Setting default fog timeout to #{Fog.timeout} seconds" end def lorem_file File.open(File.dirname(__FILE__) + '/lorem.txt', 'r') end def array_differences(array_a, array_b) (array_a - array_b) | (array_b - array_a) end fog-local-0.3.0/tests/watchr.rb0000644000004100000410000000070712677055751016407 0ustar www-datawww-dataENV['FOG_MOCK'] ||= 'true' ENV['AUTOTEST'] = 'true' ENV['WATCHR'] = '1' def file2shindo(file) result = file.sub('lib/fog/', 'tests/').gsub(/\.rb$/, '_tests.rb') end def run_shindo_test(file) if File.exist? file system("shindont #{file}") else puts "FIXME: No test #{file} [#{Time.now}]" end end watch( 'tests/.*_tests\.rb' ) do |md| run_shindo_test(md[0]) end watch( 'lib/.*\.rb' ) do |md| run_shindo_test(file2shindo(md[0])) end fog-local-0.3.0/tests/helpers/0000755000004100000410000000000012677055751016230 5ustar www-datawww-datafog-local-0.3.0/tests/helpers/formats_helper.rb0000644000004100000410000000705612677055751021577 0ustar www-datawww-datarequire "fog/schema/data_validator" # format related hackery # allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) # allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String) module Fog module Boolean; end module Nullable module Boolean; end module Integer; end module String; end module Time; end module Float; end module Hash; end module Array; end end end [FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::Boolean)} [FalseClass, TrueClass, NilClass, Fog::Boolean].each {|klass| klass.send(:include, Fog::Nullable::Boolean)} [NilClass, String].each {|klass| klass.send(:include, Fog::Nullable::String)} [NilClass, Time].each {|klass| klass.send(:include, Fog::Nullable::Time)} [Integer, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Integer)} [Float, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Float)} [Hash, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Hash)} [Array, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Array)} module Shindo class Tests # Generates a Shindo test that compares a hash schema to the result # of the passed in block returning true if they match. # # The schema that is passed in is a Hash or Array of hashes that # have Classes in place of values. When checking the schema the # value should match the Class. # # Strict mode will fail if the data has additional keys. Setting # +strict+ to +false+ will allow additional keys to appear. # # @param [Hash] schema A Hash schema # @param [Hash] options Options to change validation rules # @option options [Boolean] :allow_extra_keys # If +true+ does not fail when keys are in the data that are # not specified in the schema. This allows new values to # appear in API output without breaking the check. # @option options [Boolean] :allow_optional_rules # If +true+ does not fail if extra keys are in the schema # that do not match the data. Not recommended! # @yield Data to check with schema # # @example Using in a test # Shindo.tests("comparing welcome data against schema") do # data = {:welcome => "Hello" } # data_matches_schema(:welcome => String) { data } # end # # comparing welcome data against schema # + data matches schema # # @example Example schema # { # "id" => String, # "ram" => Integer, # "disks" => [ # { # "size" => Float # } # ], # "dns_name" => Fog::Nullable::String, # "active" => Fog::Boolean, # "created" => DateTime # } # # @return [Boolean] def data_matches_schema(schema, options = {}) test('data matches schema') do validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, schema, options) @message = validator.message unless valid valid end end # @deprecated #formats is deprecated. Use #data_matches_schema instead def formats(format, strict = true) test('has proper format') do if strict options = {:allow_extra_keys => false, :allow_optional_rules => true} else options = {:allow_extra_keys => true, :allow_optional_rules => true} end validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, format, options) @message = validator.message unless valid valid end end end end fog-local-0.3.0/tests/helpers/succeeds_helper.rb0000644000004100000410000000020612677055751021710 0ustar www-datawww-datamodule Shindo class Tests def succeeds test('succeeds') do !!instance_eval(&Proc.new) end end end end fog-local-0.3.0/tests/helpers/collection_helper.rb0000644000004100000410000000502712677055751022253 0ustar www-datawww-datadef collection_tests(collection, params = {}, mocks_implemented = true) tests('success') do tests("#new(#{params.inspect})").succeeds do pending if Fog.mocking? && !mocks_implemented collection.new(params) end tests("#create(#{params.inspect})").succeeds do pending if Fog.mocking? && !mocks_implemented @instance = collection.create(params) end # FIXME: work around for timing issue on AWS describe_instances mocks if Fog.mocking? && @instance.respond_to?(:ready?) @instance.wait_for { ready? } end tests("#all").succeeds do pending if Fog.mocking? && !mocks_implemented collection.all end if !Fog.mocking? || mocks_implemented @identity = @instance.identity end tests("#get(#{@identity})").succeeds do pending if Fog.mocking? && !mocks_implemented collection.get(@identity) end tests('Enumerable') do pending if Fog.mocking? && !mocks_implemented methods = [ 'all?', 'any?', 'find', 'detect', 'collect', 'map', 'find_index', 'flat_map', 'collect_concat', 'group_by', 'none?', 'one?' ] # JRuby 1.7.5+ issue causes a SystemStackError: stack level too deep # https://github.com/jruby/jruby/issues/1265 if RUBY_PLATFORM == "java" and JRUBY_VERSION =~ /1\.7\.[5-8]/ methods.delete('all?') end methods.each do |enum_method| if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false collection.send(enum_method) {|x| block_called = true } block_called end end end [ 'max_by','min_by' ].each do |enum_method| if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false collection.send(enum_method) {|x| block_called = true; 0 } block_called end end end end if block_given? yield(@instance) end if !Fog.mocking? || mocks_implemented @instance.destroy end end tests('failure') do if !Fog.mocking? || mocks_implemented @identity = @identity.to_s @identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) } @identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) } @identity end tests("#get('#{@identity}')").returns(nil) do pending if Fog.mocking? && !mocks_implemented collection.get(@identity) end end end fog-local-0.3.0/tests/helpers/model_helper.rb0000644000004100000410000000141412677055751021214 0ustar www-datawww-datadef model_tests(collection, params = {}, mocks_implemented = true) tests('success') do @instance = collection.new(params) tests("#save").succeeds do pending if Fog.mocking? && !mocks_implemented @instance.save end if block_given? yield(@instance) end tests("#destroy").succeeds do pending if Fog.mocking? && !mocks_implemented @instance.destroy end end end # Generates a unique identifier with a random differentiator. # Useful when rapidly re-running tests, so we don't have to wait # serveral minutes for deleted objects to disappear from the API # E.g. 'fog-test-1234' def uniq_id(base_name = 'fog-test') # random_differentiator suffix = rand(65536).to_s(16).rjust(4, '0') [base_name, suffix] * '-' end fog-local-0.3.0/tests/helpers/formats_helper_tests.rb0000644000004100000410000000702012677055751023010 0ustar www-datawww-dataShindo.tests('test_helper', 'meta') do tests('comparing welcome data against schema') do data = {:welcome => "Hello" } data_matches_schema(:welcome => String) { data } end tests('#data_matches_schema') do tests('when value matches schema expectation') do data_matches_schema({"key" => String}) { {"key" => "Value"} } end tests('when values within an array all match schema expectation') do data_matches_schema({"key" => [Integer]}) { {"key" => [1, 2]} } end tests('when nested values match schema expectation') do data_matches_schema({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} } end tests('when collection of values all match schema expectation') do data_matches_schema([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] } end tests('when collection is empty although schema covers optional members') do data_matches_schema([{"key" => String}], {:allow_optional_rules => true}) { [] } end tests('when additional keys are passed and not strict') do data_matches_schema({"key" => String}, {:allow_extra_keys => true}) { {"key" => "Value", :extra => "Bonus"} } end tests('when value is nil and schema expects NilClass') do data_matches_schema({"key" => NilClass}) { {"key" => nil} } end tests('when value and schema match as hashes') do data_matches_schema({}) { {} } end tests('when value and schema match as arrays') do data_matches_schema([]) { [] } end tests('when value is a Time') do data_matches_schema({"time" => Time}) { {"time" => Time.now} } end tests('when key is missing but value should be NilClass (#1477)') do data_matches_schema({"key" => NilClass}, {:allow_optional_rules => true}) { {} } end tests('when key is missing but value is nullable (#1477)') do data_matches_schema({"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) { {} } end end tests('#formats backwards compatible changes') do tests('when value matches schema expectation') do formats({"key" => String}) { {"key" => "Value"} } end tests('when values within an array all match schema expectation') do formats({"key" => [Integer]}) { {"key" => [1, 2]} } end tests('when nested values match schema expectation') do formats({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} } end tests('when collection of values all match schema expectation') do formats([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] } end tests('when collection is empty although schema covers optional members') do formats([{"key" => String}]) { [] } end tests('when additional keys are passed and not strict') do formats({"key" => String}, false) { {"key" => "Value", :extra => "Bonus"} } end tests('when value is nil and schema expects NilClass') do formats({"key" => NilClass}) { {"key" => nil} } end tests('when value and schema match as hashes') do formats({}) { {} } end tests('when value and schema match as arrays') do formats([]) { [] } end tests('when value is a Time') do formats({"time" => Time}) { {"time" => Time.now} } end tests('when key is missing but value should be NilClass (#1477)') do formats({"key" => NilClass}) { {} } end tests('when key is missing but value is nullable (#1477)') do formats({"key" => Fog::Nullable::String}) { {} } end end end fog-local-0.3.0/tests/helpers/mock_helper.rb0000644000004100000410000000017412677055751021047 0ustar www-datawww-data# Use so you can run in mock mode from the command line # # FOG_MOCK=true fog if ENV["FOG_MOCK"] == "true" Fog.mock! end fog-local-0.3.0/tests/helpers/schema_validator_tests.rb0000644000004100000410000000723112677055751023307 0ustar www-datawww-dataShindo.tests('Fog::Schema::DataValidator', 'meta') do validator = Fog::Schema::DataValidator.new tests('#validate') do tests('returns true') do returns(true, 'when value matches schema expectation') do validator.validate({"key" => "Value"}, {"key" => String}) end returns(true, 'when values within an array all match schema expectation') do validator.validate({"key" => [1, 2]}, {"key" => [Integer]}) end returns(true, 'when nested values match schema expectation') do validator.validate({"key" => {:nested_key => "Value"}}, {"key" => {:nested_key => String}}) end returns(true, 'when collection of values all match schema expectation') do validator.validate([{"key" => "Value"}, {"key" => "Value"}], [{"key" => String}]) end returns(true, 'when collection is empty although schema covers optional members') do validator.validate([], [{"key" => String}]) end returns(true, 'when additional keys are passed and not strict') do validator.validate({"key" => "Value", :extra => "Bonus"}, {"key" => String}, {:allow_extra_keys => true}) end returns(true, 'when value is nil and schema expects NilClass') do validator.validate({"key" => nil}, {"key" => NilClass}) end returns(true, 'when value and schema match as hashes') do validator.validate({}, {}) end returns(true, 'when value and schema match as arrays') do validator.validate([], []) end returns(true, 'when value is a Time') do validator.validate({"time" => Time.now}, {"time" => Time}) end returns(true, 'when key is missing but value should be NilClass (#1477)') do validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => true}) end returns(true, 'when key is missing but value is nullable (#1477)') do validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) end end tests('returns false') do returns(false, 'when value does not match schema expectation') do validator.validate({"key" => nil}, {"key" => String}) end returns(false, 'when key formats do not match') do validator.validate({"key" => "Value"}, {:key => String}) end returns(false, 'when additional keys are passed and strict') do validator.validate({"key" => "Missing"}, {}) end returns(false, 'when some keys do not appear') do validator.validate({}, {"key" => String}) end returns(false, 'when collection contains a member that does not match schema') do validator.validate([{"key" => "Value"}, {"key" => 5}], [{"key" => String}]) end returns(false, 'when collection has multiple schema patterns') do validator.validate([{"key" => "Value"}], [{"key" => Integer}, {"key" => String}]) end returns(false, 'when hash and array are compared') do validator.validate({}, []) end returns(false, 'when array and hash are compared') do validator.validate([], {}) end returns(false, 'when a hash is expected but another data type is found') do validator.validate({"key" => {:nested_key => []}}, {"key" => {:nested_key => {}}}) end returns(false, 'when key is missing but value should be NilClass (#1477)') do validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => false}) end returns(false, 'when key is missing but value is nullable (#1477)') do validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => false}) end end end end fog-local-0.3.0/tests/local/0000755000004100000410000000000012677055751015660 5ustar www-datawww-datafog-local-0.3.0/tests/local/models/0000755000004100000410000000000012677055751017143 5ustar www-datawww-datafog-local-0.3.0/tests/local/models/file_tests.rb0000644000004100000410000000253612677055751021637 0ustar www-datawww-dataShindo.tests('Storage[:local] | file', ["local"]) do pending if Fog.mocking? before do @options = { :local_root => Dir.mktmpdir('fog-tests') } end after do FileUtils.remove_entry_secure @options[:local_root] end tests('#public_url') do tests('when connection has an endpoint'). returns('http://example.com/files/directory/file.txt') do @options[:endpoint] = 'http://example.com/files' connection = Fog::Storage::Local.new(@options) directory = connection.directories.new(:key => 'directory') file = directory.files.new(:key => 'file.txt') file.public_url end tests('when connection has no endpoint'). returns(nil) do @options[:endpoint] = nil connection = Fog::Storage::Local.new(@options) directory = connection.directories.new(:key => 'directory') file = directory.files.new(:key => 'file.txt') file.public_url end tests('when file path has escapable characters'). returns('http://example.com/files/my%20directory/my%20file.txt') do @options[:endpoint] = 'http://example.com/files' connection = Fog::Storage::Local.new(@options) directory = connection.directories.new(:key => 'my directory') file = directory.files.new(:key => 'my file.txt') file.public_url end end end fog-local-0.3.0/tests/local/models/directory_tests.rb0000644000004100000410000000073312677055751022721 0ustar www-datawww-dataShindo.tests('Storage[:local] | directory', ["local"]) do pending if Fog.mocking? before do @options = { :local_root => Dir.mktmpdir('fog-tests') } end after do FileUtils.remove_entry_secure @options[:local_root] end tests('save') do returns('directory') do connection = Fog::Storage::Local.new(@options) connection.directories.create(:key => 'directory') connection.directories.create(:key => 'directory').key end end end fog-local-0.3.0/tests/local/models/directories_tests.rb0000644000004100000410000000105312677055751023225 0ustar www-datawww-dataShindo.tests('Storage[:local] | directories', ["local"]) do pending if Fog.mocking? @options = { :local_root => Dir.mktmpdir('fog-tests') } @collection = Fog::Storage::Local.new(@options).directories collection_tests(@collection, {:key => "fogdirtests"}, true) tests("#all") do tests("succeeds when :local_root does not exist").succeeds do FileUtils.remove_entry_secure(@options[:local_root]) @collection.all end end FileUtils.remove_entry_secure(@options[:local_root]) if File.directory?(@options[:local_root]) end fog-local-0.3.0/tests/local/storage_tests.rb0000644000004100000410000000206212677055751021073 0ustar www-datawww-dataShindo.tests('Local | storage') do pending if Fog.mocking? before do @options = { :local_root => Dir.mktmpdir('fog-tests') } end after do FileUtils.remove_entry_secure @options[:local_root] end tests('#endpoint') do tests('when no endpoint is provided'). returns(nil) do Fog::Storage::Local.new(@options).endpoint end tests('when no host is provided'). returns(nil) do @options[:scheme] = 'http' @options[:path] = '/files' @options[:port] = 80 Fog::Storage::Local.new(@options).endpoint end tests('when endpoint is provided'). returns('http://example.com/files') do @options[:endpoint] = 'http://example.com/files' Fog::Storage::Local.new(@options).endpoint end tests('when at least host option is provided'). returns('http://example.com/files') do @options[:scheme] = 'http' @options[:host] = 'example.com' @options[:path] = '/files' Fog::Storage::Local.new(@options).endpoint end end end fog-local-0.3.0/.ruby-version0000644000004100000410000000000612677055751016065 0ustar www-datawww-data2.2.0 fog-local-0.3.0/CONTRIBUTORS.md0000644000004100000410000000124412677055751015704 0ustar www-datawww-data* geemus * Lance Ivy * Paul Thornthwaite * Benjamin Manns * Sjoerd Andringa * Juris Galang * Paul Thornthwaite * Jamie Paton * Thomas Wright * Wesley Beary * Karl Freeman * Andy Lindeman * Athir Nuaimi * Brian D. Burns * Jade Tucker * James Herdman * Adam Tanner * Mark Yen fog-local-0.3.0/LICENSE.md0000644000004100000410000000216412677055751015033 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2015 [CONTRIBUTORS.md](https://github.com/fog/fog/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fog-local-0.3.0/.travis.yml0000644000004100000410000000024112677055751015532 0ustar www-datawww-datalanguage: ruby sudo: false script: bundle exec rake test rvm: - 1.9.3 - 2.0.0 - 2.1.5 - 2.2.0 - jruby-19mode env: - FOG_MOCK=true - FOG_MOCK=false fog-local-0.3.0/lib/0000755000004100000410000000000012677055751014172 5ustar www-datawww-datafog-local-0.3.0/lib/fog/0000755000004100000410000000000012677055751014745 5ustar www-datawww-datafog-local-0.3.0/lib/fog/bin/0000755000004100000410000000000012677055751015515 5ustar www-datawww-datafog-local-0.3.0/lib/fog/bin/local.rb0000644000004100000410000000127312677055751017137 0ustar www-datawww-dataclass Local < Fog::Bin class << self def class_for(key) case key when :storage Fog::Storage::Local else raise ArgumentError, "Unsupported #{self} service: #{key}" end end def [](service) @@connections ||= Hash.new do |hash, key| hash[key] = case key when :storage Fog::Logger.warning("Local[:storage] is not recommended, use Storage[:local] for portability") Fog::Storage.new(:provider => 'Local') else raise ArgumentError, "Unrecognized service: #{key.inspect}" end end @@connections[service] end def services Fog::Local.services end end end fog-local-0.3.0/lib/fog/storage/0000755000004100000410000000000012677055751016411 5ustar www-datawww-datafog-local-0.3.0/lib/fog/storage/local.rb0000644000004100000410000000501512677055751020031 0ustar www-datawww-datamodule Fog module Storage class Local < Fog::Service autoload :Directories, ::File.expand_path('../local/models/directories', __FILE__) autoload :Directory, ::File.expand_path('../local/models/directory', __FILE__) autoload :File, ::File.expand_path('../local/models/file', __FILE__) autoload :Files, ::File.expand_path('../local/models/files', __FILE__) requires :local_root recognizes :endpoint, :scheme, :host, :port, :path model_path 'fog/storage/local/models' collection :directories model :directory model :file collection :files require 'uri' class Mock attr_reader :endpoint def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end def self.reset @data = nil end def initialize(options={}) Fog::Mock.not_implemented @local_root = ::File.expand_path(options[:local_root]) @endpoint = options[:endpoint] || build_endpoint_from_options(options) end def data self.class.data[@local_root] end def local_root @local_root end def path_to(partial) ::File.join(@local_root, partial) end def reset_data self.class.data.delete(@local_root) end private def build_endpoint_from_options(options) return unless options[:host] URI::Generic.build(options).to_s end end class Real attr_reader :endpoint def initialize(options={}) @local_root = ::File.expand_path(options[:local_root]) @endpoint = options[:endpoint] || build_endpoint_from_options(options) end def local_root @local_root end def path_to(partial) ::File.join(@local_root, partial) end def copy_object(source_directory_name, source_object_name, target_directory_name, target_object_name, options={}) source_path = path_to(::File.join(source_directory_name, source_object_name)) target_path = path_to(::File.join(target_directory_name, target_object_name)) ::FileUtils.mkdir_p(::File.dirname(target_path)) ::FileUtils.copy_file(source_path, target_path) end private def build_endpoint_from_options(options) return unless options[:host] URI::Generic.build(options).to_s end end end end end fog-local-0.3.0/lib/fog/storage/local/0000755000004100000410000000000012677055751017503 5ustar www-datawww-datafog-local-0.3.0/lib/fog/storage/local/models/0000755000004100000410000000000012677055751020766 5ustar www-datawww-datafog-local-0.3.0/lib/fog/storage/local/models/directory.rb0000644000004100000410000000146112677055751023321 0ustar www-datawww-datamodule Fog module Storage class Local class Directory < Fog::Model identity :key def destroy requires :key if ::File.directory?(path) Dir.rmdir(path) true else false end end def files @files ||= begin Fog::Storage::Local::Files.new( :directory => self, :service => service ) end end def public=(new_public) new_public end def public_url nil end def save requires :key FileUtils.mkpath(path) true end private def path service.path_to(key) end end end end end fog-local-0.3.0/lib/fog/storage/local/models/files.rb0000644000004100000410000000407112677055751022417 0ustar www-datawww-datamodule Fog module Storage class Local class Files < Fog::Collection attribute :directory model Fog::Storage::Local::File def all requires :directory if directory.collection.get(directory.key) data = [] Dir.chdir(service.path_to(directory.key)) { data = Dir.glob('**/*').reject do |file| ::File.directory?(file) end.map do |key| path = file_path(key) { :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) } end } load(data) else nil end end def get(key, &block) requires :directory path = file_path(key) if ::File.exist?(path) data = { :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) } body = "" ::File.open(path) do |file| while (chunk = file.read(Excon::CHUNK_SIZE)) && (!block_given? || (block_given? && yield(chunk))) body << chunk end end data.merge!(:body => body) if !block_given? new(data) else nil end end def head(key) requires :directory path = file_path(key) if ::File.exist?(path) new({ :content_length => ::File.size(path), :key => key, :last_modified => ::File.mtime(path) }) else nil end end def new(attributes = {}) requires :directory super({ :directory => directory }.merge!(attributes)) end private def file_path(key) service.path_to(::File.join(directory.key, key)) end end end end end fog-local-0.3.0/lib/fog/storage/local/models/directories.rb0000644000004100000410000000130012677055751023621 0ustar www-datawww-datamodule Fog module Storage class Local class Directories < Fog::Collection model Fog::Storage::Local::Directory def all data = if ::File.directory?(service.local_root) Dir.entries(service.local_root).select do |entry| entry[0...1] != '.' && ::File.directory?(service.path_to(entry)) end.map do |entry| {:key => entry} end else [] end load(data) end def get(key, options = {}) if ::File.directory?(service.path_to(key)) new(:key => key) else nil end end end end end end fog-local-0.3.0/lib/fog/storage/local/models/file.rb0000644000004100000410000000736612677055751022246 0ustar www-datawww-datamodule Fog module Storage class Local class File < Fog::Model identity :key, :aliases => 'Key' attribute :content_length, :aliases => 'Content-Length', :type => :integer # attribute :content_type, :aliases => 'Content-Type' attribute :last_modified, :aliases => 'Last-Modified' require 'uri' def body attributes[:body] ||= if last_modified collection.get(identity).body else '' end end def body=(new_body) attributes[:body] = new_body end def content_type @content_type ||= begin unless (mime_types = ::MIME::Types.of(key)).empty? mime_types.first.content_type end end end def directory @directory end def copy(target_directory_key, target_file_key, options={}) requires :directory, :key service.copy_object(directory.key, key, target_directory_key, target_file_key) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.get(target_file_key) end def destroy requires :directory, :key ::File.delete(path) if ::File.exist?(path) dirs = path.split(::File::SEPARATOR)[0...-1] dirs.length.times do |index| dir_path = dirs[0..-index].join(::File::SEPARATOR) if dir_path.empty? # path starts with ::File::SEPARATOR next end # don't delete the containing directory or higher if dir_path == service.path_to(directory.key) break end pwd = Dir.pwd if ::File.exist?(dir_path) && ::File.directory?(dir_path) Dir.chdir(dir_path) if Dir.glob('*').empty? Dir.rmdir(dir_path) end Dir.chdir(pwd) end end true end def public=(new_public) new_public end def public_url requires :directory, :key if service.endpoint escaped_directory = URI.escape(directory.key) escaped_key = URI.escape(key) ::File.join(service.endpoint, escaped_directory, escaped_key) else nil end end def save(options = {}) requires :body, :directory, :key dirs = path.split(::File::SEPARATOR)[0...-1] dirs.length.times do |index| dir_path = dirs[0..index].join(::File::SEPARATOR) if dir_path.empty? # path starts with ::File::SEPARATOR next end # create directory if it doesn't already exist begin Dir.mkdir(dir_path) rescue Errno::EEXIST raise unless ::File.directory?(dir_path) end end if body.kind_of? ::File and ::File.exist?(body.path) FileUtils.cp(body.path, path) else write_file(path, body) end merge_attributes( :content_length => Fog::Storage.get_body_size(body), :last_modified => ::File.mtime(path) ) true end private def directory=(new_directory) @directory = new_directory end def path service.path_to(::File.join(directory.key, key)) end def write_file(path, content) input_io = StringIO.new(content) if content.is_a?(String) input_io ||= content ::File.open(path, 'wb') do |file| IO.copy_stream(input_io, file) end end end end end end fog-local-0.3.0/lib/fog/local.rb0000644000004100000410000000043212677055751016363 0ustar www-datawww-datarequire 'fog/core' require 'fileutils' require File.expand_path('../local/version', __FILE__) module Fog module Storage autoload :Local, File.expand_path('../storage/local', __FILE__) end module Local extend Fog::Provider service(:storage, 'Storage') end end fog-local-0.3.0/lib/fog/local/0000755000004100000410000000000012677055751016037 5ustar www-datawww-datafog-local-0.3.0/lib/fog/local/version.rb0000644000004100000410000000007212677055751020050 0ustar www-datawww-datamodule Fog module Local VERSION = '0.3.0' end end fog-local-0.3.0/lib/fog/local/storage.rb0000644000004100000410000000005112677055751020024 0ustar www-datawww-data# This file was intentionally left blank fog-local-0.3.0/.gitignore0000644000004100000410000000020112677055751015405 0ustar www-datawww-data/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.bundle *.so *.o *.a mkmf.log tests/.fog fog-local-0.3.0/CONTRIBUTING.md0000644000004100000410000000147112677055751015660 0ustar www-datawww-data## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/fog/fog/pulls). * Review open [issues](https://github.com/fog/fog/issues) for things to help on. * [Create an issue](https://github.com/fog/fog/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * Commit your changes and rebase against `fog/fog` to ensure everything is up to date. * [Submit a pull request](https://github.com/fog/fog/compare/). ### Non-Coding * Offer feedback on open [issues](https://github.com/fog/fog/issues). * Organize or volunteer at events. fog-local-0.3.0/.ruby-gemset0000644000004100000410000000001212677055751015661 0ustar www-datawww-datafog-local fog-local-0.3.0/fog-local.gemspec0000644000004100000410000000215612677055751016640 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/local/version' Gem::Specification.new do |spec| spec.name = "fog-local" spec.version = Fog::Local::VERSION spec.authors = ["Wesley Beary", "Ville Lautanala"] spec.email = ["geemus@gmail.com", "lautis@gmail.com"] spec.summary = %q{Module for the 'fog' gem to support local filesystem storage.} spec.description = %q{This library can be used as a module for `fog` or as standalone provider to use local filesystem storage.} spec.homepage = "https://github.com/fog/fog-local" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency 'bundler', '~> 1.7' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'shindo', '~> 0.3' spec.add_dependency 'fog-core', '~> 1.27' end fog-local-0.3.0/README.md0000644000004100000410000000215312677055751014704 0ustar www-datawww-data# Fog::Local ![Gem Version](https://badge.fury.io/rb/fog-local.svg) [![Build Status](https://travis-ci.org/fog/fog-local.svg?branch=master)](https://travis-ci.org/fog/fog-local) [![Dependency Status](https://gemnasium.com/fog/fog-local.svg)](https://gemnasium.com/fog/fog-local) ## Installation Add this line to your application's Gemfile: ```ruby gem 'fog-local' ``` And then execute: $ bundle Or install it yourself as: $ gem install fog-local ## Usage Initialise a `Fog::Storage` object using local provider ```ruby storage = Fog::Storage.new({ :local_root => '~/fog', :provider => 'Local' }) ``` This can then be used like any other [Fog storage](http://fog.io/storage/). ```ruby directory = storage.directories.create(:key => 'data') directory.files.create(:body => 'Hello World!', :key => 'hello_world.txt') ``` ## Contributing 1. Fork it ( https://github.com/fog/fog-local/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request