class ClassMattr::Proxy

Public Class Methods

new(host) click to toggle source
# File lib/lib/proxy.rb, line 6
def initialize host
  @host = host
end

Public Instance Methods

_get(name) click to toggle source
# File lib/lib/proxy.rb, line 22
def _get name
  for klass in @host.ancestors.map(&:to_s)
    return {} if klass == 'ClassMattr'

    hash = MATTRS.dig(klass, name.to_sym)
    return hash if hash
  end

  raise 'ClassMattr not included?'
end
_set(name) click to toggle source
# File lib/lib/proxy.rb, line 10
def _set name
  while el = @@mattrs.shift
    klass, trait, opts = el[0], el[1].to_sym, el[2]

    MATTRS[klass] ||= {}
    el = MATTRS[klass][name.to_sym] ||= {}

    # default value if true if no argument provided
    el[trait] = opts.nil? ? true : opts
  end
end
get_hash() click to toggle source
# File lib/lib/proxy.rb, line 33
def get_hash
  name = :__mattr_tmp
  _set name
  MATTRS[@host.to_s].delete(name)
end
method_missing(name, value=nil) click to toggle source
# File lib/lib/proxy.rb, line 39
def method_missing name, value=nil
  @@mattrs.push [@host.to_s, name.to_s, value]
end