Module: Runar::DSL::ClassMethods
- Defined in:
- lib/runar/dsl.rb
Instance Method Summary collapse
-
#method_added(method_name) ⇒ Object
Hook: when a method is defined, attach pending visibility/param metadata.
- #params(**param_types) ⇒ Object
-
#prop(name, type, readonly: false, default: :__no_default__) ⇒ Object
Declare a typed property on a Runar contract.
-
#runar_defaults ⇒ Object
Returns the hash of { property_name => default_value } for this class and all its superclasses (merged, with the most specific class winning).
- #runar_methods ⇒ Object
- #runar_properties ⇒ Object
- #runar_public(**param_types) ⇒ Object
Instance Method Details
#method_added(method_name) ⇒ Object
Hook: when a method is defined, attach pending visibility/param metadata.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/runar/dsl.rb', line 58 def method_added(method_name) return if method_name == :initialize return unless @_runar_next_visibility || @_runar_next_param_types @_runar_methods ||= {} @_runar_methods[method_name] = { visibility: @_runar_next_visibility || :private, param_types: @_runar_next_param_types || {} } @_runar_next_visibility = nil @_runar_next_param_types = nil super end |
#params(**param_types) ⇒ Object
53 54 55 |
# File 'lib/runar/dsl.rb', line 53 def params(**param_types) @_runar_next_param_types = param_types end |
#prop(name, type, readonly: false, default: :__no_default__) ⇒ Object
Declare a typed property on a Runar contract.
Options:
readonly: true -- generates only a reader; the property cannot be
mutated by contract methods.
default: value -- provides an initial value so the property is
excluded from the auto-generated constructor.
The default is set before the developer-written
initialize runs.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/runar/dsl.rb', line 24 def prop(name, type, readonly: false, default: :__no_default__) @_runar_properties ||= [] is_readonly = readonly || (self < Runar::SmartContract && !(self < Runar::StatefulSmartContract)) if is_readonly attr_reader name else attr_accessor name end has_default = default != :__no_default__ if has_default @_runar_defaults ||= {} @_runar_defaults[name] = default end @_runar_properties << { name: name, type: type, readonly: is_readonly, default: has_default ? default : nil } end |
#runar_defaults ⇒ Object
Returns the hash of { property_name => default_value } for this class and all its superclasses (merged, with the most specific class winning).
44 45 46 |
# File 'lib/runar/dsl.rb', line 44 def runar_defaults @_runar_defaults || {} end |
#runar_methods ⇒ Object
76 77 78 |
# File 'lib/runar/dsl.rb', line 76 def runar_methods @_runar_methods || {} end |
#runar_properties ⇒ Object
72 73 74 |
# File 'lib/runar/dsl.rb', line 72 def runar_properties @_runar_properties || [] end |
#runar_public(**param_types) ⇒ Object
48 49 50 51 |
# File 'lib/runar/dsl.rb', line 48 def runar_public(**param_types) @_runar_next_visibility = :public @_runar_next_param_types = param_types unless param_types.empty? end |