Method: Delorean::BaseModule::BaseClass._get_attr

Defined in:
lib/delorean/base.rb

._get_attr(obj, attr, _e) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/delorean/base.rb', line 92

def self._get_attr(obj, attr, _e)
  # REALLY FIXME: this really needs to be another "when" in the
  # case statement below. However, Gemini appears to create Hash
  # objects when running Delorean modules in delayed jobs that
  # return true when we called obj.instance_of?(Hash) and do not
  # work with the "case/when" matcher!!!  For now, this is a
  # hacky workaround.  This is likely some sort of Ruby bug.
  return _get_hash_attr(obj, attr, _e) if obj.instance_of?(Hash)

  # NOTE: should keep this function consistent with _index
  case obj
  when nil
    # FIXME: even Javascript which is superpermissive raises an
    # exception on null getattr.
    return nil
  when NodeCall
    return obj.evaluate(attr)
  when OpenStruct
    return obj[attr.to_sym]
  when Class
    return obj.send((attr + POST).to_sym, _e) if obj < BaseClass
  end

  begin
    _instance_call(obj, attr, [], _e)
  rescue StandardError => exc
    raise(
      InvalidGetAttribute,
      "attr lookup failed: '#{attr}' on <#{obj.class}> #{obj} - #{exc}"
    )
  end
end