Class: WelltreatStoreFramework::Controller::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/welltreat_store_framework/controller.rb

Constant Summary collapse

STATUS_OK =
200

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



77
78
79
80
81
82
83
84
# File 'lib/welltreat_store_framework/controller.rb', line 77

def initialize
  @status   = STATUS_OK
  @headers  = { 'Content-Type' => 'text/html' }
  @content  = nil
  @template = nil
  @layout   = :default
  @values   = { }
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



74
75
76
# File 'lib/welltreat_store_framework/controller.rb', line 74

def content
  @content
end

#controller_nameObject

Returns the value of attribute controller_name.



74
75
76
# File 'lib/welltreat_store_framework/controller.rb', line 74

def controller_name
  @controller_name
end

#headersObject

Returns the value of attribute headers.



74
75
76
# File 'lib/welltreat_store_framework/controller.rb', line 74

def headers
  @headers
end

#layoutObject

Returns the value of attribute layout.



74
75
76
# File 'lib/welltreat_store_framework/controller.rb', line 74

def layout
  @layout
end

#statusObject

Returns the value of attribute status.



74
75
76
# File 'lib/welltreat_store_framework/controller.rb', line 74

def status
  @status
end

#templateObject

Returns the value of attribute template.



74
75
76
# File 'lib/welltreat_store_framework/controller.rb', line 74

def template
  @template
end

#valuesObject

Returns the value of attribute values.



74
75
76
# File 'lib/welltreat_store_framework/controller.rb', line 74

def values
  @values
end

Instance Method Details

#[](k) ⇒ Object



107
108
109
# File 'lib/welltreat_store_framework/controller.rb', line 107

def [](k)
  self.get(k)
end

#add_header(k, v) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/welltreat_store_framework/controller.rb', line 86

def add_header(k, v)
  case k.to_s
    when 'content_type', 'format'
      @headers['Content-Type'] = v
    else
      @headers[k] = v
  end
end

#exists?(k) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/welltreat_store_framework/controller.rb', line 111

def exists?(k)
  @values.include?(k)
end

#get(k) ⇒ Object



103
104
105
# File 'lib/welltreat_store_framework/controller.rb', line 103

def get(k)
  @values[k]
end

#get_header(k) ⇒ Object



95
96
97
# File 'lib/welltreat_store_framework/controller.rb', line 95

def get_header(k)
  @headers[k]
end

#present?(k) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/welltreat_store_framework/controller.rb', line 115

def present?(k)
  exists?(k) && get(k).present?
end

#redirect?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/welltreat_store_framework/controller.rb', line 125

def redirect?
  [301, 302, 303, 307].include? self.status
end

#redirect_to(path, status = 302) ⇒ Object



119
120
121
122
123
# File 'lib/welltreat_store_framework/controller.rb', line 119

def redirect_to(path, status = 302)
  self.status = status
  self.add_header("Location", path)
  self.content = ''
end

#set(k, v) ⇒ Object



99
100
101
# File 'lib/welltreat_store_framework/controller.rb', line 99

def set(k, v)
  @values[k] = v
end