Module: Kernel

Defined in:
lib/aws/s3/extensions.rb

Instance Method Summary collapse

Instance Method Details

#__called_from__Object



138
139
140
# File 'lib/aws/s3/extensions.rb', line 138

def __called_from__
  caller[1][/`([^']+)'/, 1]
end

#__method__(depth = 0) ⇒ Object



134
135
136
# File 'lib/aws/s3/extensions.rb', line 134

def __method__(depth = 0)
  caller[depth][/`([^']+)'/, 1]
end

#expirable_memoize(reload = false, storage = nil) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/aws/s3/extensions.rb', line 142

def expirable_memoize(reload = false, storage = nil)
  current_method = RUBY_VERSION > '1.8.7' ? __called_from__ : __method__(1)
  storage = "@#{storage || current_method}"
  if reload 
    instance_variable_set(storage, nil)
  else
    if cache = instance_variable_get(storage)
      return cache
    end
  end
  instance_variable_set(storage, yield)
end

#require_library_or_gem(library, gem_name = nil) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/aws/s3/extensions.rb', line 155

def require_library_or_gem(library, gem_name = nil)
  if RUBY_VERSION >= '1.9'
    gem(gem_name || library, '>=0') 
  end
  require library
rescue LoadError => library_not_installed
  begin
    require 'rubygems'
    require library
  rescue LoadError
    raise library_not_installed
  end
end