Class: WelltreatStoreFramework::StoreApp

Inherits:
Object
  • Object
show all
Includes:
HamlRenderer
Defined in:
lib/welltreat_store_framework/store_app.rb

Defined Under Namespace

Classes: ActionNotFound, AppStack, ControllerNotFound, ExecutionError, TemplateNotFound, TemplateRenderingError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HamlRenderer

#_full_layout_path, #_full_partial_template_path, #_full_template_path, #_haml_engines, #_singleton_haml_instance, #render!

Constructor Details

#initialize(attrs = { }) ⇒ StoreApp

Default constructor with attribute hash, if attribute hash is passed it will set value through setter accessors



55
56
57
58
59
60
61
# File 'lib/welltreat_store_framework/store_app.rb', line 55

def initialize(attrs = { })
  if attrs.present?
    attrs.each do |k, v|
      self.send(:"#{k}=", v)
    end
  end
end

Instance Attribute Details

#assets_pathObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def assets_path
  @assets_path
end

#config_pathObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def config_path
  @config_path
end

#controllers_pathObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def controllers_path
  @controllers_path
end

#models_pathObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def models_path
  @models_path
end

#nameObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def name
  @name
end

#partition_objectObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def partition_object
  @partition_object
end

#pathObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def path
  @path
end

#routes_pathObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def routes_path
  @routes_path
end

#startedObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def started
  @started
end

#viewsObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def views
  @views
end

#views_pathObject

Declare attribute accessors



49
50
51
# File 'lib/welltreat_store_framework/store_app.rb', line 49

def views_path
  @views_path
end

Instance Method Details

#baseObject



93
94
95
# File 'lib/welltreat_store_framework/store_app.rb', line 93

def base;
  _base_module
end

#call(env) ⇒ Object

Make it rack compatible



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/welltreat_store_framework/store_app.rb', line 134

def call(env)
  request  = WelltreatStoreFramework::Controller::Request.initialize_from_env(env)
  response = WelltreatStoreFramework::Controller::Response.new
  options = {
      session: env['rack.session']
  }

  dispatch request.path, request, response, options
  render! request, response, options

  [response.status, response.headers, [response.content]]
end

#controllersObject



101
102
103
# File 'lib/welltreat_store_framework/store_app.rb', line 101

def controllers
  base::Controllers
end

#dispatch(path, request, response, options) ⇒ Object

Handle request for the specified path and request Return status and html content string



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/welltreat_store_framework/store_app.rb', line 108

def dispatch(path, request, response, options)
  if WelltreatStoreFramework::Core.configuration.auto_reload
    restart
  end

  begin
    case path
      when '/'
        _execute_action(:Home, :index, request, response, options)
      else
        _controller_name, _action, _id = self.send(:_extract_path, path)
        request.send(:set_param, :id, _id)

        _execute_action(_controller_name, _action, request, response, options)
    end

    # Handle 404
  rescue WelltreatStoreFramework::StoreApp::ControllerNotFound
    _execute_action(:Home, :not_found, request, response, options)

  rescue WelltreatStoreFramework::StoreApp::ActionNotFound
    _execute_action(:Home, :not_found, request, response, options)
  end
end

#modelsObject



97
98
99
# File 'lib/welltreat_store_framework/store_app.rb', line 97

def models
  base::Models
end

#restartObject

Stop and start application



83
84
85
86
87
88
89
90
91
# File 'lib/welltreat_store_framework/store_app.rb', line 83

def restart
  if self.started
    self.stop
    self.start
    true
  else
    false
  end
end

#startObject

Start application Return true if successful otherwise false



65
66
67
68
# File 'lib/welltreat_store_framework/store_app.rb', line 65

def start
  _bootstrap!
  self.started = true
end

#stopObject

Dispose and stop application Return true if successful otherwise false



72
73
74
75
76
77
78
79
80
# File 'lib/welltreat_store_framework/store_app.rb', line 72

def stop
  if self.started
    _dispose!
    self.started = false
    true
  else
    false
  end
end