class U3dCore::Globals

all these attributes are false by default and can be set overriden temporarily using a

with_attr(value) do
  something
end

construct

Attributes

do_not_login[W]
log_timestamps[W]
use_keychain[W]
verbose[W]

Public Class Methods

method_missing(method_sym, *arguments, &block) click to toggle source
Calls superclass method
# File lib/u3d_core/globals.rb, line 54
def method_missing(method_sym, *arguments, &block)
  if method_sym.to_s =~ /^with_(.*)$/
    if attributes.include? Regexp.last_match(1)
      with(Regexp.last_match(1).to_sym, arguments.first, &block)
    else
      super
    end
  elsif method_sym.to_s =~ /^(.*)\?$/
    if attributes.include? Regexp.last_match(1)
      is?(Regexp.last_match(1).to_sym)
    else
      super
    end
  else
    super
  end
end
respond_to_missing?(method_sym, include_private = false) click to toggle source
Calls superclass method
# File lib/u3d_core/globals.rb, line 72
def respond_to_missing?(method_sym, include_private = false)
  # rubocop:disable GuardClause
  if method_sym.to_s =~ /^with_(.*)$/
    return attributes.include? Regexp.last_match(1)
  elsif method_sym.to_s =~ /^(.*)\?$/
    return attributes.include? Regexp.last_match(1)
  else
    super
  end
  # rubocop:enable GuardClause
end

Private Class Methods

attributes() click to toggle source
# File lib/u3d_core/globals.rb, line 35
def attributes
  @attributes ||= ((methods - public_instance_methods).grep(/=$/) - %i[<= >=]).map do |s|
    a = s.to_s
    a[0..(a.length - 2)] # remove the '='
  end
end
is?(attr) click to toggle source
# File lib/u3d_core/globals.rb, line 50
def is?(attr)
  instance_variable_get("@#{attr}")
end
with(attr, value) { || ... } click to toggle source
# File lib/u3d_core/globals.rb, line 42
def with(attr, value)
  orig_attr = send("#{attr}?")
  send("#{attr}=", value)
  yield if block_given?
ensure
  send("#{attr}=", orig_attr)
end