Class: Object

Inherits:
BasicObject
Defined in:
lib/util/attr_chain.rb,
lib/util/ruby_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attr_chain(variable_name, *attr_configs) ⇒ void

This method returns an undefined value.

Configurable accessor methods

See Also:



246
247
248
# File 'lib/util/attr_chain.rb', line 246

def self.attr_chain(variable_name, *attr_configs)
  AttrChain.new(self, variable_name, attr_configs)
end

.const_get_full(full_class_name) ⇒ Object

Resolves fully qualified class named including modules: Ki::KiCommand



132
133
134
135
136
137
138
# File 'lib/util/ruby_extensions.rb', line 132

def Object.const_get_full(full_class_name)
  class_or_module = self
  full_class_name.split("::").each do |name|
    class_or_module = class_or_module.const_get(name)
  end
  class_or_module
end

Instance Method Details

#show_errors(&block) ⇒ Object

if block raises an exception outputs the error message. returns block’s exit value or reraises the exception



122
123
124
125
126
127
128
129
# File 'lib/util/ruby_extensions.rb', line 122

def show_errors(&block)
  begin
    block.call
  rescue Exception => e
    puts "Exception '#{e.message}':\n#{e.backtrace.join("\n")}"
    raise
  end
end

#try(retries, retry_sleep, &block) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/util/ruby_extensions.rb', line 140

def try(retries, retry_sleep, &block)
  c = 0
  start = Time.now
  while c < retries
    begin
      return block.call(c+1)
    rescue Exception => e
      c += 1
      if c < retries
        sleep retry_sleep
      else
        raise e.class, e.message + " (tried #{c} times, waited #{sprintf("%.2f", Time.now - start)} seconds)", e.backtrace
      end
    end
  end
end