class Object

Constants

ROOT_MODEL_NAMES
RUNNING_SERVER
WEBSOCKET_OPTIONS

Load websocket options once at boot The ENV option lets it kick in automatically if we're on heroku.

Public Instance Methods

blank?() click to toggle source

An object is blank if it's false, empty, or a whitespace string. For example, '', ' ', nil, [], and {} are all blank.

This simplifies:

if address.nil? || address.empty?

…to:

if address.blank?
# File lib/volt/extra_core/blank.rb, line 12
def blank?
  respond_to?(:empty?) ? empty? : !self
end
deep_clone() click to toggle source

TODO: Need a real implementation of this

# File lib/volt/extra_core/object.rb, line 16
def deep_clone
  if RUBY_PLATFORM == 'opal'
    Volt::EJSON.parse(Volt::EJSON.stringify(self))
  else
    Marshal.load(Marshal.dump(self))
  end
end
html_inspect() click to toggle source
# File lib/volt/extra_core/object.rb, line 11
def html_inspect
  inspect.gsub('<', '&lt;').gsub('>', '&gt;')
end
instance_values() click to toggle source

Setup a default pretty_inspect alias_method :pretty_inspect, :inspect

# File lib/volt/extra_core/object.rb, line 7
def instance_values
  Hash[instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }]
end
present?() click to toggle source

An object is present if it's not blank?.

# File lib/volt/extra_core/blank.rb, line 17
def present?
  !blank?
end
stringify_keys() click to toggle source
# File lib/volt/extra_core/stringify_keys.rb, line 2
def stringify_keys
  each_with_object({}) do |(key, value), hash|
    hash[key.to_s] = value
  end
end
symbolize_keys() click to toggle source
# File lib/volt/extra_core/stringify_keys.rb, line 8
def symbolize_keys
  each_with_object({}) do |(key, value), hash|
    hash[key.to_sym] = value
  end
end
then(&block) click to toggle source

Convert a non-promise value into a resolved promise. Resolve the block if it takes one.

# File lib/volt/extra_core/object.rb, line 26
def then(&block)
  promisify_and_run_method(:then, &block)
end
try(*a) { |self| ... } click to toggle source

def fail(&block)

promisify_and_run_method(:fail, &block)

end

# File lib/volt/extra_core/object.rb, line 34
def try(*a, &b)
  if a.empty? && block_given?
    yield self
  else
    public_send(*a, &b) if respond_to?(a.first)
  end
end

Private Instance Methods

promisify_and_run_method(method_name, &block) click to toggle source
# File lib/volt/extra_core/object.rb, line 43
def promisify_and_run_method(method_name, &block)
  promise = Promise.new.resolve(self)

  promise = promise.send(method_name, &block) if block

  promise
end