Class: Opushon::Option Private

Inherits:
Object
  • Object
show all
Defined in:
lib/opushon/option.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: '', description: '', request: {}, response: {}) ⇒ Option

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Option.

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/opushon/option.rb', line 28

def initialize(title: '', description: '', request: {}, response: {})
  raise ArgumentError, "title #{title.inspect}"             unless title.is_a?(String)
  raise ArgumentError, "description #{description.inspect}" unless description.is_a?(String)
  raise ArgumentError, "request #{request.inspect}"         unless request.is_a?(Hash)
  raise ArgumentError, "response #{response.inspect}"       unless response.is_a?(Hash)

  @title        = title
  @description  = description
  @request      = Request.load(request)
  @response     = Response.load(response)
end

Instance Attribute Details

#descriptionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/opushon/option.rb', line 26

def description
  @description
end

#requestObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/opushon/option.rb', line 26

def request
  @request
end

#responseObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/opushon/option.rb', line 26

def response
  @response
end

#titleObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/opushon/option.rb', line 26

def title
  @title
end

Class Method Details

.load(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/opushon/option.rb', line 8

def self.load(hash)
  raise ArgumentError, "hash #{hash.inspect}" unless hash.is_a?(Hash)

  title       = hash.fetch('title',       nil)
  description = hash.fetch('description', nil)
  request     = hash.fetch('request',     nil)
  response    = hash.fetch('response',    nil)

  hash = {
    title:        title,
    description:  description,
    request:      request,
    response:     response
  }.compact

  new(**hash)
end

Instance Method Details

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
43
44
45
46
47
# File 'lib/opushon/option.rb', line 40

def to_h
  {
    title:        title,
    description:  description,
    request:      request.to_h,
    response:     response.to_h
  }
end