Module: Kernel

Defined in:
lib/amazon/mws/lib/extensions.rb

Instance Method Summary collapse

Instance Method Details

#__called_from__Object



89
90
91
# File 'lib/amazon/mws/lib/extensions.rb', line 89

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

#__method__(depth = 0) ⇒ Object



85
86
87
# File 'lib/amazon/mws/lib/extensions.rb', line 85

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

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



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/amazon/mws/lib/extensions.rb', line 93

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



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/amazon/mws/lib/extensions.rb', line 106

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