Class: Module

Inherits:
Object show all
Defined in:
lib/aliyun/oss/extensions.rb

Instance Method Summary collapse

Instance Method Details

#const_missing_from_oss_library(sym) ⇒ Object Also known as: const_missing

Transforms MarcelBucket into

class MarcelBucket < Aliyun::OSS::Bucket
  set_current_bucket_to 'marcel'
end


235
236
237
238
239
240
241
242
243
# File 'lib/aliyun/oss/extensions.rb', line 235

def const_missing_from_oss_library(sym)
  if sym.to_s =~ /^(\w+)(Bucket|OSSObject)$/
    const = const_set(sym, Class.new(Aliyun::OSS.const_get($2)))
    const.current_bucket = $1.underscore
    const
  else
    const_missing_not_from_oss_library(sym)
  end
end

#constant(name, value) ⇒ Object



219
220
221
222
223
224
225
226
227
228
# File 'lib/aliyun/oss/extensions.rb', line 219

def constant(name, value)
  unless const_defined?(name)
    const_set(name, value) 
    module_eval(<<-EVAL, __FILE__, __LINE__)
      def self.#{name.to_s.downcase}
        #{name.to_s}
      end
    EVAL
  end
end

#memoized(method_name) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/aliyun/oss/extensions.rb', line 207

def memoized(method_name)
  original_method = "unmemoized_#{method_name}_#{Time.now.to_i}"
  alias_method original_method, method_name
  module_eval(<<-EVAL, __FILE__, __LINE__)
    def #{method_name}(reload = false, *args, &block)
      expirable_memoize(reload) do
        send(:#{original_method}, *args, &block)
      end
    end
  EVAL
end