Module: Textus::Contract::DSL
- Included in:
- Maintenance::KeyDeletePrefix, Maintenance::KeyMvPrefix, Maintenance::Migrate, Maintenance::RuleLint, Maintenance::ZoneMv, Read::Boot, Read::Get, Read::List, Read::Pulse, Read::Rules, Read::SchemaEnvelope, Write::FetchAll, Write::FetchWorker, Write::Propose, Write::Put
- Defined in:
- lib/textus/contract.rb
Overview
Mixed onto a use-case class via ‘extend`. Calls accumulate into ivars, frozen into a Spec on first read of `.contract`.
Instance Method Summary collapse
- #arg(name, type, required: false, positional: false, session_default: nil, description: nil) ⇒ Object
-
#contract ⇒ Object
rubocop:disable Naming/MemoizedInstanceVariableName (@__verb, @__args, etc.) and avoid name collision with user-defined ‘@contract`.
- #contract? ⇒ Boolean
- #response(&blk) ⇒ Object
- #summary(text = nil) ⇒ Object
- #surfaces(*list) ⇒ Object
- #verb(name = nil) ⇒ Object
Instance Method Details
#arg(name, type, required: false, positional: false, session_default: nil, description: nil) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/textus/contract.rb', line 73 def arg(name, type, required: false, positional: false, session_default: nil, description: nil) raise "contract already built; declare args before reading .contract" if defined?(@__contract) && @__contract (@__args ||= []) << Arg.new( name: name, type: type, required: required, positional: positional, session_default: session_default, description: description ) end |
#contract ⇒ Object
rubocop:disable Naming/MemoizedInstanceVariableName (@__verb, @__args, etc.) and avoid name collision with user-defined ‘@contract`.
94 95 96 97 98 99 100 101 102 |
# File 'lib/textus/contract.rb', line 94 def contract @__contract ||= Spec.new( verb: @__verb, summary: @__summary, args: (@__args || []).freeze, surfaces: (@__surfaces || []).freeze, response: response, ) end |
#contract? ⇒ Boolean
87 88 89 |
# File 'lib/textus/contract.rb', line 87 def contract? !@__verb.nil? end |
#response(&blk) ⇒ Object
82 83 84 85 |
# File 'lib/textus/contract.rb', line 82 def response(&blk) @__response = blk if blk @__response || ->(v) { v } end |
#summary(text = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/textus/contract.rb', line 53 def summary(text = nil) if text raise "contract already built; declare summary before reading .contract" if defined?(@__contract) && @__contract @__summary = text else @__summary end end |
#surfaces(*list) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/textus/contract.rb', line 63 def surfaces(*list) if list.empty? @__surfaces ||= [] else raise "contract already built; declare surfaces before reading .contract" if defined?(@__contract) && @__contract @__surfaces = list end end |
#verb(name = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/textus/contract.rb', line 43 def verb(name = nil) if name raise "contract already built; declare verb before reading .contract" if defined?(@__contract) && @__contract @__verb = name else @__verb end end |