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.



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

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

Instance Method Details

#concept(credit) ⇒ Object



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

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

#connect(path, &block) ⇒ Object



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

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

#default_attributesObject



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

def default_attributes
  { resources: [] }
end

#delete(path, &block) ⇒ Object



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

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

#description(description) ⇒ Object



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

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

#generateObject



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

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

  super
end

#get(path, &block) ⇒ Object



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

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

#head(path, &block) ⇒ Object



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

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

#implementation(progress, credit) ⇒ Object



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

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

#nameObject



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

def name
  @attributes[:name] = name
end

#patch(path, &block) ⇒ Object



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

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

#post(path, &block) ⇒ Object



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

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

#put(path, &block) ⇒ Object



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

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

#resource(path, &block) ⇒ Object



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

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



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

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

#timestamp(timestamp) ⇒ Object



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

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

  @attributes[:timestamp] = timestamp
end

#trace(path, &block) ⇒ Object



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

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

#url(url) ⇒ Object



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

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