Skip to content

Commit

Permalink
make deprecation a bit more flexible and deprecate setters
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed May 4, 2010
1 parent 3197c25 commit 4a5faf5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lib/fog/aws/models/s3/directory.rb
Expand Up @@ -8,8 +8,9 @@ module S3
class Directory < Fog::Model
extend Fog::Deprecation
deprecate(:name, :key)
deprecate(:name=, :key=)

identity :key, ['Name', 'name', :name]
identity :key, ['Name', 'name']

attribute :creation_date, 'CreationDate'

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/deprecation.rb
Expand Up @@ -8,7 +8,7 @@ def #{older}(*args)
warning = "[yellow][WARN] #{self} => ##{older} is deprecated, use ##{newer} instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
#{newer}(*args)
send(:#{newer}, *args)
end
EOS
end
Expand Down
8 changes: 4 additions & 4 deletions lib/fog/local/models/directories.rb
Expand Up @@ -24,14 +24,14 @@ def all
data = Dir.entries(connection.local_root).select do |entry|
entry[0...1] != '.' && ::File.directory?(connection.path_to(entry))
end.map do |entry|
{:name => entry}
{:key => entry}
end
load(data)
end

def get(name)
if ::File.directory?(connection.path_to(name))
new(:name => name)
def get(key)
if ::File.directory?(connection.path_to(key))
new(:key => key)
else
nil
end
Expand Down
11 changes: 7 additions & 4 deletions lib/fog/local/models/directory.rb
Expand Up @@ -5,11 +5,14 @@ module Fog
module Local

class Directory < Fog::Model
extend Fog::Deprecation
deprecate(:name, :key)
deprecate(:name=, :key=)

identity :name
identity :key

def destroy
requires :name
requires :key

if ::File.directory?(path)
Dir.rmdir(path)
Expand All @@ -29,7 +32,7 @@ def files
end

def save
requires :name
requires :key

Dir.mkdir(path)
true
Expand All @@ -38,7 +41,7 @@ def save
private

def path
connection.path_to(name)
connection.path_to(key)
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/local/models/file.rb
Expand Up @@ -49,7 +49,7 @@ def directory=(new_directory)
end

def path
connection.path_to(::File.join(directory.name, key))
connection.path_to(::File.join(directory.key, key))
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/fog/local/models/files.rb
Expand Up @@ -9,8 +9,8 @@ class Files < Fog::Collection
model Fog::Local::File

def all
if directory.collection.get(directory.name)
data = Dir.entries(connection.path_to(directory.name)).select do |key|
if directory.collection.get(directory.key)
data = Dir.entries(connection.path_to(directory.key)).select do |key|
key[0...1] != '.' && !::File.directory?(connection.path_to(key))
end.map do |key|
path = file_path(key)
Expand Down Expand Up @@ -66,7 +66,7 @@ def directory=(new_directory)
end

def file_path(key)
connection.path_to(::File.join(directory.name, key))
connection.path_to(::File.join(directory.key, key))
end

end
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/rackspace/models/files/directory.rb
Expand Up @@ -8,8 +8,9 @@ module Files
class Directory < Fog::Model
extend Fog::Deprecation
deprecate(:name, :key)
deprecate(:name=, :key=)

identity :key, ['name', :name]
identity :key, ['name']

attribute :bytes
attribute :count
Expand Down

0 comments on commit 4a5faf5

Please sign in to comment.