Class: LxDocs::UseCase
- Inherits:
-
Object
- Object
- LxDocs::UseCase
- Defined in:
- lib/lx_docs/use_case.rb
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
Class Method Summary collapse
Instance Method Summary collapse
- #description(value) ⇒ Object
- #example(value) ⇒ Object
- #includes(other) ⇒ Object
-
#initialize(title, version, controller = nil, action = nil) ⇒ UseCase
constructor
A new instance of UseCase.
- #parameter(name, **opts) ⇒ Object
- #response(code, body = nil, description = nil) ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(title, version, controller = nil, action = nil) ⇒ UseCase
Returns a new instance of UseCase.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lx_docs/use_case.rb', line 18 def initialize(title, version, controller = nil, action = nil) @version = version @controller = controller @action = action @info = { title: title, description: '', parameters: {}, responses: [], examples: [], includes: [] } end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
16 17 18 |
# File 'lib/lx_docs/use_case.rb', line 16 def info @info end |
Class Method Details
.add(title, version, *args, &block) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/lx_docs/use_case.rb', line 9 def self.add(title, version, *args, &block) self.defined[version] ||= {} self.defined[version][title] = new(title, version, *args).tap do |use_case| use_case.instance_eval(&block) end end |
.defined ⇒ Object
5 6 7 |
# File 'lib/lx_docs/use_case.rb', line 5 def self.defined @use_cases ||= {} end |
Instance Method Details
#description(value) ⇒ Object
32 33 34 |
# File 'lib/lx_docs/use_case.rb', line 32 def description(value) @info[:description] = value end |
#example(value) ⇒ Object
40 41 42 |
# File 'lib/lx_docs/use_case.rb', line 40 def example(value) @info[:examples] << value end |
#includes(other) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/lx_docs/use_case.rb', line 52 def includes(other) @info[:includes] << other other = LxDocs::UseCase.defined[@version][other] @info[:parameters].merge!(other.info[:parameters]) @info[:responses] |= other.info[:responses] @info[:examples] |= other.info[:examples] end |
#parameter(name, **opts) ⇒ Object
36 37 38 |
# File 'lib/lx_docs/use_case.rb', line 36 def parameter(name, **opts) @info[:parameters][name.to_sym] = opts end |
#response(code, body = nil, description = nil) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/lx_docs/use_case.rb', line 44 def response(code, body = nil, description = nil) @info[:responses] << { code: code, body: body, description: description } end |
#to_json(*args) ⇒ Object
60 61 62 |
# File 'lib/lx_docs/use_case.rb', line 60 def to_json(*args) @info.to_json(*args) end |