Class: Orthoses::ActiveSupport::Delegation::Resource
- Inherits:
-
Object
- Object
- Orthoses::ActiveSupport::Delegation::Resource
- Defined in:
- lib/orthoses/active_support/delegation.rb
Instance Method Summary collapse
- #build_definition(typename, kind) ⇒ Object
- #build_signature(mod_name, name, kind, argument) ⇒ Object
- #find(mod_name, name, kind, argument) ⇒ Object
-
#initialize(store) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
Instance Method Details
#build_definition(typename, kind) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/orthoses/active_support/delegation.rb', line 92 def build_definition(typename, kind) case kind when :instance @definition_builder.build_instance(typename) when :singleton @definition_builder.build_singleton(typename) else raise "bug" end rescue RuntimeError => e if e..match?(/\AUnknown name for/) nil else raise end end |
#build_signature(mod_name, name, kind, argument) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/orthoses/active_support/delegation.rb', line 109 def build_signature(mod_name, name, kind, argument) tag, type = find(mod_name, name, kind, argument) case tag when :single "def #{name}: () -> #{type}" when :multi "def #{name}: #{type.join(' | ')}" else nil end end |
#find(mod_name, name, kind, argument) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/orthoses/active_support/delegation.rb', line 82 def find(mod_name, name, kind, argument) typename = TypeName(mod_name).absolute! if definition_method = build_definition(typename, kind)&.methods&.[](name) # found in env return [:multi, definition_method.defs.map(&:type)] end resolve_type_by_name(@store[mod_name].to_decl.members, name, kind, argument) end |