Module: ActionFigure::Core::ClassMethods
- Defined in:
- lib/action_figure/core.rb
Overview
DSL class methods extended into action classes: params_schema, rules, entry_point.
Note: ActionFigure does not support class inheritance. params_schema, rules, and entry_point store state in class-level instance variables that are not inherited by subclasses. Define each action class independently.
Instance Method Summary collapse
- #api_version(value = :_unset) ⇒ Object
- #contract ⇒ Object
-
#entry_point(name) ⇒ Object
Declares an alternative entry point method name (e.g. entry_point :search).
- #entry_point_name ⇒ Object
- #params_schema(&block) ⇒ Object
- #rules(&block) ⇒ Object
Instance Method Details
#api_version(value = :_unset) ⇒ Object
83 84 85 |
# File 'lib/action_figure/core.rb', line 83 def api_version(value = :_unset) value == :_unset ? @api_version : (@api_version = value) end |
#contract ⇒ Object
87 88 89 90 91 |
# File 'lib/action_figure/core.rb', line 87 def contract return nil unless @params_schema_block @contract ||= build_contract end |
#entry_point(name) ⇒ Object
Declares an alternative entry point method name (e.g. entry_point :search). May only be called once per class. Inheritance of action classes is not supported —params_schema, rules, and entry_point are not inherited by subclasses.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/action_figure/core.rb', line 65 def entry_point(name) if @entry_point_name raise ArgumentError, "entry_point already defined as '#{@entry_point_name}' — " \ "each action class may declare only one entry point" end @explicit_entry_point = true @entry_point_name = name singleton_class.define_method(name) do |**kwargs| notify { new.validated_call(**kwargs) } end end |
#entry_point_name ⇒ Object
79 80 81 |
# File 'lib/action_figure/core.rb', line 79 def entry_point_name @entry_point_name end |
#params_schema(&block) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/action_figure/core.rb', line 45 def params_schema(&block) if @params_schema_block raise ArgumentError, "params_schema already defined — each action class may declare only one schema" end @params_schema_block = block @contract = nil end |
#rules(&block) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/action_figure/core.rb', line 55 def rules(&block) raise ArgumentError, "rules requires params_schema to be defined" unless @params_schema_block @rules_block = block @contract = nil end |