Module: Pakyow::Support::Definable::ClassMethods Private
- Defined in:
- lib/pakyow/support/definable.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #__inherited_state ⇒ Object readonly private
- #__state ⇒ Object readonly private
Instance Method Summary collapse
-
#define(&block) ⇒ Object
private
Define state for the object.
- #inherited(subclass) ⇒ Object private
-
#stateful(name, object, &stateful_block) ⇒ Object
private
Register a type of state that can be defined.
Instance Attribute Details
#__inherited_state ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/pakyow/support/definable.rb', line 68 def __inherited_state @__inherited_state end |
#__state ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/pakyow/support/definable.rb', line 68 def __state @__state end |
Instance Method Details
#define(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Define state for the object.
140 141 142 |
# File 'lib/pakyow/support/definable.rb', line 140 def define(&block) class_exec(&block) end |
#inherited(subclass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 76 77 |
# File 'lib/pakyow/support/definable.rb', line 70 def inherited(subclass) super subclass.instance_variable_set(:@__inherited_state, @__state.deep_dup) subclass.instance_variable_set(:@__state, @__state.each_with_object({}) { |(name, state_instance), state| state[name] = State.new(name, state_instance.object) }) end |
#stateful(name, object, &stateful_block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Register a type of state that can be defined.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/pakyow/support/definable.rb', line 114 def stateful(name, object, &stateful_block) name = name.to_sym @__state[name] = State.new(name, object) plural_name = Support.inflector.pluralize(name.to_s).to_sym within = if __object_name ObjectNamespace.new(*__object_name.namespace.parts.dup.concat([plural_name])) else self end method_body = Proc.new do |*args, priority: :default, **opts, &block| return @__state[name] if block.nil? stateful_block.call(args, opts) if stateful_block object.make(*args, within: within, **opts, &block).tap do |state| @__state[name].register(state, priority: priority) end end define_method name, &method_body define_singleton_method name, &method_body end |