Class: Happy::Extras::Scriptable
- Inherits:
-
Controller
- Object
- Controller
- Happy::Extras::Scriptable
- 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
Instance Method Summary collapse
- #get_proc_for_script(name) ⇒ Object
- #load_script(name) ⇒ Object
- #procs ⇒ Object
- #reload_script?(name) ⇒ Boolean
- #route ⇒ Object
- #run_script(name) ⇒ Object
Methods inherited from Controller
#app, #current_url, helpers, #initialize, #params, #request, #response, #root_url, #session
Methods included from Helpers::I18n
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
Methods included from Controller::Configurable
Methods included from Controller::Rackable
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
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.(File.join(settings[:directory], name)) File.read(file_name) end |
#procs ⇒ Object
29 30 31 |
# File 'lib/happy/extras/scriptable.rb', line 29 def procs @procs ||= {} end |
#reload_script?(name) ⇒ Boolean
20 21 22 |
# File 'lib/happy/extras/scriptable.rb', line 20 def reload_script?(name) !procs[name] || Happy.env.development? end |
#route ⇒ Object
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 |