Class: Useless::Doc::DSL::API

Inherits:
Object
  • Object
show all
Includes:
Member
Defined in:
lib/useless/doc/dsl.rb

Instance Method Summary collapse

Methods included from Member

included

Constructor Details

#initialize(attributes = {}) ⇒ API

Returns a new instance of API.



104
105
106
107
# File 'lib/useless/doc/dsl.rb', line 104

def initialize(attributes = {})
  @resource_dsls = []
  super
end

Instance Method Details

#concept(credit) ⇒ Object



141
142
143
144
# File 'lib/useless/doc/dsl.rb', line 141

def concept(credit)
  concept = Doc::Core::Stage.new(credit: [credit].flatten)
  @attributes[:concept] = concept
end

#connect(path, &block) ⇒ Object



184
185
186
# File 'lib/useless/doc/dsl.rb', line 184

def connect(path, &block)
  resource(path).connect(&block)
end

#default_attributesObject



109
110
111
# File 'lib/useless/doc/dsl.rb', line 109

def default_attributes
  { resources: [] }
end

#delete(path, &block) ⇒ Object



176
177
178
# File 'lib/useless/doc/dsl.rb', line 176

def delete(path, &block)
  resource(path).delete(&block)
end

#description(description) ⇒ Object



129
130
131
# File 'lib/useless/doc/dsl.rb', line 129

def description(description)
  @attributes[:description] = description
end

#generateObject



113
114
115
116
117
118
119
# File 'lib/useless/doc/dsl.rb', line 113

def generate
  @attributes[:resources] = @resource_dsls.map do |resource_dsl|
    resource_dsl.generate
  end

  super
end

#get(path, &block) ⇒ Object



156
157
158
# File 'lib/useless/doc/dsl.rb', line 156

def get(path, &block)
  resource(path).get(&block)
end

#head(path, &block) ⇒ Object



160
161
162
# File 'lib/useless/doc/dsl.rb', line 160

def head(path, &block)
  resource(path).head(&block)
end

#implementation(progress, credit) ⇒ Object



151
152
153
154
# File 'lib/useless/doc/dsl.rb', line 151

def implementation(progress, credit)
  implementation = Doc::Core::Stage.new(progress: progress, credit: [credit].flatten)
  @attributes[:implementation] = implementation
end

#nameObject



121
122
123
# File 'lib/useless/doc/dsl.rb', line 121

def name
  @attributes[:name] = name
end

#patch(path, &block) ⇒ Object



172
173
174
# File 'lib/useless/doc/dsl.rb', line 172

def patch(path, &block)
  resource(path).patch(&block)
end

#post(path, &block) ⇒ Object



164
165
166
# File 'lib/useless/doc/dsl.rb', line 164

def post(path, &block)
  resource(path).post(&block)
end

#put(path, &block) ⇒ Object



168
169
170
# File 'lib/useless/doc/dsl.rb', line 168

def put(path, &block)
  resource(path).put(&block)
end

#resource(path, &block) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/useless/doc/dsl.rb', line 188

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

#specification(progress, credit) ⇒ Object



146
147
148
149
# File 'lib/useless/doc/dsl.rb', line 146

def specification(progress, credit)
  specification = Doc::Core::Stage.new(progress: progress, credit: [credit].flatten)
  @attributes[:specification] = specification
end

#timestamp(timestamp) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/useless/doc/dsl.rb', line 133

def timestamp(timestamp)
  if timestamp.is_a?(String)
    timestamp = Time.parse(timestamp)
  end

  @attributes[:timestamp] = timestamp
end

#trace(path, &block) ⇒ Object



180
181
182
# File 'lib/useless/doc/dsl.rb', line 180

def trace(path, &block)
  resource(path).trace(&block)
end

#url(url) ⇒ Object



125
126
127
# File 'lib/useless/doc/dsl.rb', line 125

def url(url)
  @attributes[:url] = url
end