fog-local-0.2.1/0000755000175000017500000000000012521404541014641 5ustar balasankarcbalasankarcfog-local-0.2.1/LICENSE.md0000644000175000017500000000216412521404541016250 0ustar balasankarcbalasankarcThe 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.2.1/Gemfile0000644000175000017500000000013612521404541016134 0ustar balasankarcbalasankarcsource 'https://rubygems.org' # Specify your gem's dependencies in fog-local.gemspec gemspec fog-local-0.2.1/.gitignore0000644000175000017500000000020112521404541016622 0ustar balasankarcbalasankarc/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.bundle *.so *.o *.a mkmf.log tests/.fog fog-local-0.2.1/Rakefile0000644000175000017500000000024112521404541016303 0ustar balasankarcbalasankarcrequire "bundler/gem_tasks" task :default => :test mock = ENV['FOG_MOCK'] || 'false' task :test do sh("export FOG_MOCK=#{mock} && bundle exec shindont") end fog-local-0.2.1/metadata.yml0000644000175000017500000000651112521404541017147 0ustar balasankarcbalasankarc--- !ruby/object:Gem::Specification name: fog-local version: !ruby/object:Gem::Version version: 0.2.1 platform: ruby authors: - Wesley Beary - Ville Lautanala autorequire: bindir: bin cert_chain: [] date: 2015-04-10 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.7' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.7' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' - !ruby/object:Gem::Dependency name: shindo requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.3' - !ruby/object:Gem::Dependency name: fog-core requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.27' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.27' description: |- This library can be used as a module for `fog` or as standalone provider to use local filesystem storage. email: - geemus@gmail.com - lautis@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".travis.yml" - CONTRIBUTING.md - CONTRIBUTORS.md - Gemfile - LICENSE.md - README.md - Rakefile - fog-local.gemspec - lib/fog/bin/local.rb - lib/fog/local.rb - lib/fog/local/storage.rb - lib/fog/local/version.rb - lib/fog/storage/local.rb - lib/fog/storage/local/models/directories.rb - lib/fog/storage/local/models/directory.rb - lib/fog/storage/local/models/file.rb - lib/fog/storage/local/models/files.rb - tests/helper.rb - tests/helpers/collection_helper.rb - tests/helpers/formats_helper.rb - tests/helpers/formats_helper_tests.rb - tests/helpers/mock_helper.rb - tests/helpers/model_helper.rb - tests/helpers/schema_validator_tests.rb - tests/helpers/succeeds_helper.rb - tests/local/models/directories_tests.rb - tests/local/models/directory_tests.rb - tests/local/models/file_tests.rb - tests/local/storage_tests.rb - tests/watchr.rb homepage: https://github.com/fog/fog-local licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.5 signing_key: specification_version: 4 summary: Module for the 'fog' gem to support local filesystem storage. test_files: [] fog-local-0.2.1/tests/0000755000175000017500000000000012521404541016003 5ustar balasankarcbalasankarcfog-local-0.2.1/tests/watchr.rb0000644000175000017500000000070712521404541017624 0ustar balasankarcbalasankarcENV['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.2.1/tests/helper.rb0000644000175000017500000000144512521404541017613 0ustar balasankarcbalasankarcbegin 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.2.1/tests/local/0000755000175000017500000000000012521404541017075 5ustar balasankarcbalasankarcfog-local-0.2.1/tests/local/models/0000755000175000017500000000000012521404541020360 5ustar balasankarcbalasankarcfog-local-0.2.1/tests/local/models/file_tests.rb0000644000175000017500000000253612521404541023054 0ustar balasankarcbalasankarcShindo.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.2.1/tests/local/models/directories_tests.rb0000644000175000017500000000105312521404541024442 0ustar balasankarcbalasankarcShindo.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.2.1/tests/local/models/directory_tests.rb0000644000175000017500000000073312521404541024136 0ustar balasankarcbalasankarcShindo.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.2.1/tests/local/storage_tests.rb0000644000175000017500000000206212521404541022310 0ustar balasankarcbalasankarcShindo.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.2.1/tests/helpers/0000755000175000017500000000000012521404541017445 5ustar balasankarcbalasankarcfog-local-0.2.1/tests/helpers/collection_helper.rb0000644000175000017500000000502712521404541023470 0ustar balasankarcbalasankarcdef 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.2.1/tests/helpers/mock_helper.rb0000644000175000017500000000017412521404541022264 0ustar balasankarcbalasankarc# 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.2.1/tests/helpers/model_helper.rb0000644000175000017500000000141412521404541022431 0ustar balasankarcbalasankarcdef 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.2.1/tests/helpers/succeeds_helper.rb0000644000175000017500000000020612521404541023125 0ustar balasankarcbalasankarcmodule Shindo class Tests def succeeds test('succeeds') do !!instance_eval(&Proc.new) end end end end fog-local-0.2.1/tests/helpers/formats_helper_tests.rb0000644000175000017500000000702012521404541024225 0ustar balasankarcbalasankarcShindo.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.2.1/tests/helpers/schema_validator_tests.rb0000644000175000017500000000723112521404541024524 0ustar balasankarcbalasankarcShindo.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.2.1/tests/helpers/formats_helper.rb0000644000175000017500000000705612521404541023014 0ustar balasankarcbalasankarcrequire "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.2.1/lib/0000755000175000017500000000000012521404541015407 5ustar balasankarcbalasankarcfog-local-0.2.1/lib/fog/0000755000175000017500000000000012521404541016162 5ustar balasankarcbalasankarcfog-local-0.2.1/lib/fog/local/0000755000175000017500000000000012521404541017254 5ustar balasankarcbalasankarcfog-local-0.2.1/lib/fog/local/version.rb0000644000175000017500000000007212521404541021265 0ustar balasankarcbalasankarcmodule Fog module Local VERSION = '0.2.1' end end fog-local-0.2.1/lib/fog/local/storage.rb0000644000175000017500000000005112521404541021241 0ustar balasankarcbalasankarc# This file was intentionally left blank fog-local-0.2.1/lib/fog/bin/0000755000175000017500000000000012521404541016732 5ustar balasankarcbalasankarcfog-local-0.2.1/lib/fog/bin/local.rb0000644000175000017500000000127312521404541020354 0ustar balasankarcbalasankarcclass 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.2.1/lib/fog/local.rb0000644000175000017500000000043212521404541017600 0ustar balasankarcbalasankarcrequire '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.2.1/lib/fog/storage/0000755000175000017500000000000012521404541017626 5ustar balasankarcbalasankarcfog-local-0.2.1/lib/fog/storage/local/0000755000175000017500000000000012521404541020720 5ustar balasankarcbalasankarcfog-local-0.2.1/lib/fog/storage/local/models/0000755000175000017500000000000012521404541022203 5ustar balasankarcbalasankarcfog-local-0.2.1/lib/fog/storage/local/models/directory.rb0000644000175000017500000000146112521404541024536 0ustar balasankarcbalasankarcmodule 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.2.1/lib/fog/storage/local/models/files.rb0000644000175000017500000000406512521404541023637 0ustar balasankarcbalasankarcmodule 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) } if block_given? file = ::File.open(path) while (chunk = file.read(Excon::CHUNK_SIZE)) && yield(chunk); end file.close new(data) else body = ::File.read(path) new(data.merge!(:body => body)) end 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.2.1/lib/fog/storage/local/models/file.rb0000644000175000017500000000716512521404541023460 0ustar balasankarcbalasankarcmodule 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 file = ::File.new(path, 'wb') if body.is_a?(String) file.write(body) elsif body.kind_of? ::File and ::File.exist?(body.path) FileUtils.cp(body.path, path) else file.write(body.read) end file.close 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 end end end end fog-local-0.2.1/lib/fog/storage/local/models/directories.rb0000644000175000017500000000130012521404541025036 0ustar balasankarcbalasankarcmodule 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.2.1/lib/fog/storage/local.rb0000644000175000017500000000501512521404541021246 0ustar balasankarcbalasankarcmodule 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.2.1/CONTRIBUTING.md0000644000175000017500000000147112521404541017075 0ustar balasankarcbalasankarc## 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.2.1/CONTRIBUTORS.md0000644000175000017500000000124412521404541017121 0ustar balasankarcbalasankarc* 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.2.1/fog-local.gemspec0000644000175000017500000000215612521404541020055 0ustar balasankarcbalasankarc# 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.2.1/.travis.yml0000644000175000017500000000024112521404541016747 0ustar balasankarcbalasankarclanguage: 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.2.1/README.md0000644000175000017500000000215312521404541016121 0ustar balasankarcbalasankarc# 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