Module: SPQR::Util
- Included in:
- App, QmfSchemaProcessor, Raiseable::ClassMixins
- Defined in:
- lib/spqr/utils.rb
Instance Method Summary collapse
-
#const_lookup(fqcn) ⇒ Object
turns a string name of a constant into the value of that constant; returns that value, or nil if fqcn doesn’t correspond to a valid constant.
- #encode_argument(arg, destination) ⇒ Object
- #get_xml_constant(xml_key, dictionary) ⇒ Object
- #manageable?(k) ⇒ Boolean
- #symbolize_dict(k, kz = nil) ⇒ Object
Instance Method Details
#const_lookup(fqcn) ⇒ Object
turns a string name of a constant into the value of that constant; returns that value, or nil if fqcn doesn’t correspond to a valid constant
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/spqr/utils.rb', line 101 def const_lookup(fqcn) # FIXME: move out of App, into a utils module? hierarchy = fqcn.split("::") const = hierarchy.pop mod = Kernel hierarchy.each do |m| mod = mod.const_get(m) end mod.const_get(const) rescue nil end |
#encode_argument(arg, destination) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/spqr/utils.rb', line 112 def encode_argument(arg, destination) arg_opts = arg. arg_opts[:desc] ||= arg.description if (arg.description && arg.description.is_a?(String)) arg_opts[:dir] ||= get_xml_constant(arg.direction.to_s, ::SPQR::XmlConstants::Direction) if arg.respond_to? :direction arg_name = arg.name.to_s arg_type = get_xml_constant(arg.kind.to_s, ::SPQR::XmlConstants::Type) destination.add_argument(Qmf::SchemaArgument.new(arg_name, arg_type, arg_opts)) end |
#get_xml_constant(xml_key, dictionary) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/spqr/utils.rb', line 88 def get_xml_constant(xml_key, dictionary) string_val = dictionary[xml_key] return xml_key unless string_val actual_val = const_lookup(string_val) return string_val unless actual_val return actual_val end |
#manageable?(k) ⇒ Boolean
122 123 124 |
# File 'lib/spqr/utils.rb', line 122 def manageable?(k) k.is_a?(Class) && (k.included_modules.include?(::SPQR::Manageable) || k.included_modules.include?(::SPQR::Raiseable)) end |
#symbolize_dict(k, kz = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/spqr/utils.rb', line 77 def symbolize_dict(k, kz=nil) k2 = {} kz ||= k.keys k.keys.each do |key| k2[key.to_sym] = k[key] if (kz.include?(key) || kz.include?(key.to_sym)) end k2 end |