Class: Happy::Extras::Scriptable

Inherits:
Controller show all
Defined in:
lib/happy/extras/scriptable.rb

Constant Summary

Constants inherited from Controller

Controller::CASCADING_SETTINGS

Instance Attribute Summary

Attributes inherited from Controller

#env, #processed_path, #unprocessed_path

Attributes included from Helpers::Rendering

#output_buffer

Instance Method Summary collapse

Methods inherited from Controller

#app, #current_url, helpers, #initialize, #params, #request, #response, #root_url, #session

Methods included from Helpers::I18n

#localize, #translate

Methods included from Helpers::Rendering

#capture_template_block, #concat_output, #render, #render_resource, #render_template, #with_output_buffer

Methods included from Helpers::Html

#escape_html, #html_tag, #html_tag_attributes, #link_to, #preserve, #url_for

Methods included from Controller::Permissions

#permissions

Methods included from Controller::Configurable

included, #set, #settings

Methods included from Controller::Rackable

#handle_request, included

Methods included from Controller::Actions

#cache_control, #content_type, #halt!, #header, #layout, #max_age, #only_if_path_matches, #redirect!, #run, #serve!

Methods included from Controller::Routing

#on, #path_to_regexp

Constructor Details

This class inherits a constructor from Happy::Controller

Instance Method Details

#get_proc_for_script(name) ⇒ Object


13
14
15
16
17
18
# File 'lib/happy/extras/scriptable.rb', line 13

def get_proc_for_script(name)
  if reload_script?(name)
    procs[name] = eval "lambda { %s }" % load_script(name)
  end
  procs[name]
end

#load_script(name) ⇒ Object


24
25
26
27
# File 'lib/happy/extras/scriptable.rb', line 24

def load_script(name)
  file_name = File.expand_path(File.join(settings[:directory], name))
  File.read(file_name)
end

#procsObject


29
30
31
# File 'lib/happy/extras/scriptable.rb', line 29

def procs
  @procs ||= {}
end

#reload_script?(name) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/happy/extras/scriptable.rb', line 20

def reload_script?(name)
  !procs[name] || Happy.env.development?
end

#routeObject


4
5
6
7
# File 'lib/happy/extras/scriptable.rb', line 4

def route
  run_script 'permissions.rb'
  run_script 'route.rb'
end

#run_script(name) ⇒ Object


9
10
11
# File 'lib/happy/extras/scriptable.rb', line 9

def run_script(name)
  instance_exec &get_proc_for_script(name)
end