Class: Menilite::Controller
- Inherits:
-
Object
- Object
- Menilite::Controller
- Defined in:
- lib/menilite/controller.rb
Defined Under Namespace
Classes: ActionInfo
Class Method Summary collapse
- .action(name, options = {}, &block) ⇒ Object
- .action_info ⇒ Object
- .before_action(options = {}, &block) ⇒ Object
- .before_action_handlers ⇒ Object
Instance Method Summary collapse
-
#initialize(session, settings) ⇒ Controller
constructor
A new instance of Controller.
- #session ⇒ Object
- #settings ⇒ Object
Constructor Details
#initialize(session, settings) ⇒ Controller
Returns a new instance of Controller.
8 9 10 11 |
# File 'lib/menilite/controller.rb', line 8 def initialize(session, settings) @settings = settings @session = session end |
Class Method Details
.action(name, options = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/menilite/controller.rb', line 33 def action(name, = {}, &block) action_info[name.to_s] = ActionInfo.new(name, block.parameters, ) if RUBY_ENGINE == 'opal' method = Proc.new do |*args, &callback| # todo: should adopt keyword parameters action_url = self.respond_to?(:namespace) ? "api/#{self.namespace}/#{name}" : "api/#{name}" post_data = {} post_data[:args] = args Menilite::Http.post_json(action_url, post_data) do on :success do |res| callback.call(:success, res) if callback end on :failure do |res| callback.call(:failure, res) if callback end end end self.instance_eval do define_singleton_method(name, method) end else self.instance_eval do define_method(name, block) end end end |
.action_info ⇒ Object
23 24 25 |
# File 'lib/menilite/controller.rb', line 23 def action_info @action_info ||= {} end |
.before_action(options = {}, &block) ⇒ Object
60 61 62 |
# File 'lib/menilite/controller.rb', line 60 def before_action( = {}, &block) before_action_handlers << { proc: block, options: } end |
.before_action_handlers ⇒ Object
27 28 29 |
# File 'lib/menilite/controller.rb', line 27 def before_action_handlers @before_action_handlers ||= [] end |
Instance Method Details
#session ⇒ Object
14 15 16 |
# File 'lib/menilite/controller.rb', line 14 def session @session end |
#settings ⇒ Object
18 19 20 |
# File 'lib/menilite/controller.rb', line 18 def settings @settings end |