Class: Useless::Doc::DSL::API
- Inherits:
-
Object
- Object
- Useless::Doc::DSL::API
- Includes:
- Member
- Defined in:
- lib/useless/doc/dsl.rb
Instance Method Summary collapse
- #connect(path, &block) ⇒ Object
- #default_attributes ⇒ Object
- #delete(path, &block) ⇒ Object
- #description(description) ⇒ Object
- #generate ⇒ Object
- #get(path, &block) ⇒ Object
- #head(path, &block) ⇒ Object
-
#initialize(attributes = {}) ⇒ API
constructor
A new instance of API.
- #name ⇒ Object
- #patch(path, &block) ⇒ Object
- #post(path, &block) ⇒ Object
- #put(path, &block) ⇒ Object
- #resource(path, &block) ⇒ Object
- #timestamp(timestamp) ⇒ Object
- #trace(path, &block) ⇒ Object
- #url(url) ⇒ Object
Methods included from Member
Constructor Details
#initialize(attributes = {}) ⇒ API
Returns a new instance of API.
96 97 98 99 |
# File 'lib/useless/doc/dsl.rb', line 96 def initialize(attributes = {}) @resource_dsls = [] super end |
Instance Method Details
#connect(path, &block) ⇒ Object
161 162 163 |
# File 'lib/useless/doc/dsl.rb', line 161 def connect(path, &block) resource(path).connect(&block) end |
#default_attributes ⇒ Object
101 102 103 |
# File 'lib/useless/doc/dsl.rb', line 101 def default_attributes { resources: [] } end |
#delete(path, &block) ⇒ Object
153 154 155 |
# File 'lib/useless/doc/dsl.rb', line 153 def delete(path, &block) resource(path).delete(&block) end |
#description(description) ⇒ Object
121 122 123 |
# File 'lib/useless/doc/dsl.rb', line 121 def description(description) @attributes[:description] = description end |
#generate ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/useless/doc/dsl.rb', line 105 def generate @attributes[:resources] = @resource_dsls.map do |resource_dsl| resource_dsl.generate end super end |
#get(path, &block) ⇒ Object
133 134 135 |
# File 'lib/useless/doc/dsl.rb', line 133 def get(path, &block) resource(path).get(&block) end |
#head(path, &block) ⇒ Object
137 138 139 |
# File 'lib/useless/doc/dsl.rb', line 137 def head(path, &block) resource(path).head(&block) end |
#name ⇒ Object
113 114 115 |
# File 'lib/useless/doc/dsl.rb', line 113 def name @attributes[:name] = name end |
#patch(path, &block) ⇒ Object
149 150 151 |
# File 'lib/useless/doc/dsl.rb', line 149 def patch(path, &block) resource(path).patch(&block) end |
#post(path, &block) ⇒ Object
141 142 143 |
# File 'lib/useless/doc/dsl.rb', line 141 def post(path, &block) resource(path).post(&block) end |
#put(path, &block) ⇒ Object
145 146 147 |
# File 'lib/useless/doc/dsl.rb', line 145 def put(path, &block) resource(path).put(&block) end |
#resource(path, &block) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/useless/doc/dsl.rb', line 165 def resource(path, &block) resource_dsl = @resource_dsls.find do |resource| resource.attributes[:path] == path end unless resource_dsl resource_dsl = Resource.new(path: path) @resource_dsls << resource_dsl end resource_dsl.instance_eval(&block) if block_given? resource_dsl end |
#timestamp(timestamp) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/useless/doc/dsl.rb', line 125 def () if .is_a?(String) = Time.parse() end @attributes[:timestamp] = end |
#trace(path, &block) ⇒ Object
157 158 159 |
# File 'lib/useless/doc/dsl.rb', line 157 def trace(path, &block) resource(path).trace(&block) end |
#url(url) ⇒ Object
117 118 119 |
# File 'lib/useless/doc/dsl.rb', line 117 def url(url) @attributes[:url] = url end |