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

#connect(path, &block) ⇒ Object



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

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



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

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



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

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

#head(path, &block) ⇒ Object



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

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

#nameObject



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

def name
  @attributes[:name] = name
end

#patch(path, &block) ⇒ Object



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

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

#post(path, &block) ⇒ Object



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

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

#put(path, &block) ⇒ Object



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

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

#resource(path, &block) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/useless/doc/dsl.rb', line 173

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



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



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

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