Class: ApiBlueprint::Model

Inherits:
Struct
  • Object
show all
Extended by:
ActiveModel::Callbacks, ActiveModel::Naming, Dry::Configurable
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
lib/api-blueprint/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

new

Class Method Details

.blueprint(http_method, url, options = {}, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/api-blueprint/model.rb', line 19

def self.blueprint(http_method, url, options = {}, &block)
  blueprint_opts = {
    http_method: http_method,
    url: Url.new(config.host, url).to_s,
    creates: self,
    parser: config.parser,
    replacements: config.replacements,
    builder: config.builder,
    log_responses: config.log_responses
  }.merge(options)

  if block_given?
    blueprint_opts[:after_build] = block
  end

  Blueprint.new blueprint_opts
end

.collection(blueprints) ⇒ Object



37
38
39
# File 'lib/api-blueprint/model.rb', line 37

def self.collection(blueprints)
  Collection.new blueprints, self
end

Instance Method Details

#api_request_success?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/api-blueprint/model.rb', line 41

def api_request_success?
  response_status.present? && (200...299).include?(response_status)
end

#as_json(options = nil) ⇒ Object



45
46
47
# File 'lib/api-blueprint/model.rb', line 45

def as_json(options = nil)
  super(options).except :response_headers, :response_status
end