plezi 0.12.22 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/LICENSE.txt +17 -18
  4. data/README.md +54 -698
  5. data/Rakefile +7 -4
  6. data/bin/config.ru +22 -0
  7. data/{test → bin}/console +4 -6
  8. data/bin/hello_world +52 -0
  9. data/bin/setup +8 -0
  10. data/exe/plezi +145 -0
  11. data/lib/plezi.rb +24 -137
  12. data/lib/plezi/activation.rb +28 -0
  13. data/lib/plezi/api.rb +62 -0
  14. data/lib/plezi/controller/controller.rb +259 -0
  15. data/lib/plezi/controller/controller_class.rb +176 -0
  16. data/lib/plezi/controller/cookies.rb +40 -0
  17. data/lib/plezi/helpers.rb +60 -0
  18. data/lib/plezi/rake.rb +2 -24
  19. data/lib/plezi/render/erb.rb +34 -0
  20. data/lib/plezi/render/has_cache.rb +36 -0
  21. data/lib/plezi/render/markdown.rb +63 -0
  22. data/lib/plezi/render/render.rb +49 -0
  23. data/lib/plezi/render/sass.rb +55 -0
  24. data/lib/plezi/render/slim.rb +33 -0
  25. data/lib/plezi/router/adclient.rb +23 -0
  26. data/lib/plezi/router/assets.rb +67 -0
  27. data/lib/plezi/router/errors.rb +29 -0
  28. data/lib/plezi/router/route.rb +112 -0
  29. data/lib/plezi/router/router.rb +120 -0
  30. data/lib/plezi/version.rb +1 -1
  31. data/lib/plezi/websockets/message_dispatch.rb +91 -0
  32. data/lib/plezi/websockets/redis.rb +55 -0
  33. data/plezi.gemspec +25 -16
  34. data/resources/404.erb +5 -4
  35. data/resources/500.erb +5 -4
  36. data/resources/{500.html → 503.html} +8 -9
  37. data/resources/client.js +253 -0
  38. data/resources/config.ru +5 -36
  39. data/resources/ctrlr.rb +34 -0
  40. data/resources/gemfile +4 -0
  41. data/resources/mini_app.rb +28 -82
  42. data/resources/mini_exec +7 -0
  43. data/resources/mini_welcome_page.html +0 -0
  44. data/resources/procfile +3 -0
  45. data/resources/rakefile +4 -8
  46. data/resources/routes.rb +9 -26
  47. data/resources/{websockets.js → simple-client.js} +3 -3
  48. metadata +60 -85
  49. data/bin/plezi +0 -104
  50. data/docs/async_helpers.md +0 -245
  51. data/docs/controllers.md +0 -27
  52. data/docs/logging.md +0 -49
  53. data/docs/routes.md +0 -209
  54. data/docs/websockets.md +0 -213
  55. data/lib/plezi/builders/ac_model.rb +0 -59
  56. data/lib/plezi/builders/app_builder.rb +0 -137
  57. data/lib/plezi/builders/builder.rb +0 -43
  58. data/lib/plezi/builders/form_builder.rb +0 -27
  59. data/lib/plezi/common/api.rb +0 -92
  60. data/lib/plezi/common/cache.rb +0 -122
  61. data/lib/plezi/common/defer.rb +0 -21
  62. data/lib/plezi/common/dsl.rb +0 -94
  63. data/lib/plezi/common/redis.rb +0 -65
  64. data/lib/plezi/common/renderer.rb +0 -141
  65. data/lib/plezi/common/settings.rb +0 -52
  66. data/lib/plezi/handlers/controller_core.rb +0 -106
  67. data/lib/plezi/handlers/controller_magic.rb +0 -284
  68. data/lib/plezi/handlers/http_router.rb +0 -205
  69. data/lib/plezi/handlers/placebo.rb +0 -112
  70. data/lib/plezi/handlers/route.rb +0 -216
  71. data/lib/plezi/handlers/session.rb +0 -109
  72. data/lib/plezi/handlers/stubs.rb +0 -156
  73. data/lib/plezi/handlers/ws_identity.rb +0 -253
  74. data/lib/plezi/handlers/ws_object.rb +0 -308
  75. data/lib/plezi/helpers/http_sender.rb +0 -84
  76. data/lib/plezi/helpers/magic_helpers.rb +0 -104
  77. data/lib/plezi/helpers/mime_types.rb +0 -1995
  78. data/lib/plezi/oauth.rb +0 -5
  79. data/lib/plezi/oauth/auth_controller.rb +0 -229
  80. data/logo/dark.png +0 -0
  81. data/logo/light.png +0 -0
  82. data/logo/sign.png +0 -0
  83. data/resources/404.haml +0 -121
  84. data/resources/404.html +0 -124
  85. data/resources/404.slim +0 -120
  86. data/resources/500.haml +0 -120
  87. data/resources/500.slim +0 -120
  88. data/resources/Gemfile +0 -86
  89. data/resources/code.rb +0 -8
  90. data/resources/controller.rb +0 -142
  91. data/resources/database.yml +0 -33
  92. data/resources/db_ac_config.rb +0 -59
  93. data/resources/db_dm_config.rb +0 -51
  94. data/resources/db_sequel_config.rb +0 -33
  95. data/resources/en.yml +0 -204
  96. data/resources/haml_config.rb +0 -6
  97. data/resources/i18n_config.rb +0 -14
  98. data/resources/initialize.rb +0 -49
  99. data/resources/mini_exec.rb +0 -7
  100. data/resources/oauth_config.rb +0 -24
  101. data/resources/plezi_client.js +0 -198
  102. data/resources/plezi_websockets.html +0 -47
  103. data/resources/redis_config.rb +0 -42
  104. data/resources/slim_config.rb +0 -11
  105. data/resources/welcome_page.html +0 -272
  106. data/test/dispatch +0 -58
  107. data/test/hello_world +0 -13
  108. data/test/plezi_tests.rb +0 -581
@@ -1,21 +0,0 @@
1
-
2
- module Plezi
3
-
4
- module_function
5
-
6
- # Defers any missing methods to the Iodine Library.
7
- def method_missing name, *args, &block
8
- return super unless REACTOR_METHODS.include? name
9
- ::Iodine.__send__ name, *args, &block
10
- end
11
- # Defers any missing methods to the Iodine Library.
12
- def respond_to_missing?(name, include_private = false)
13
- REACTOR_METHODS.include?(name) || super
14
- end
15
-
16
- protected
17
-
18
- REACTOR_METHODS = ::Iodine.public_methods(false)
19
-
20
- end
21
-
@@ -1,94 +0,0 @@
1
- unless defined? PLEZI_NON_DSL
2
-
3
- # shortcut for Plezi.listen. Deprecated.
4
- #
5
- def listen(params = {})
6
- Plezi.listen params
7
- end
8
-
9
- # adds a virtul host or switches to an existing host, for routes setup or parameters update.
10
- #
11
- # accepts:
12
- # host_name: a String with the full host name (i.e. "www.google.com" / "mail.google.com")
13
- # params:: any of the parameters accepted by the {Plezi.host} command.
14
- #
15
- # If no host is specified or host name is `false`, the default host would be set as the active host and returned.
16
- def host(host_name = false, params = {})
17
- Plezi.host host_name, params
18
- end
19
-
20
- # adds a route to the last (or default) host
21
- #
22
- # path:: the path for the route
23
- # controller:: The controller class which will accept the route.
24
- #
25
- # `path` parameters has a few options:
26
- #
27
- # * `path` can be a Regexp object, forcing the all the logic into controller (typically using the before method).
28
- #
29
- # * simple String paths are assumed to be basic RESTful paths:
30
- #
31
- # route "/users", Controller => route "/users/(:id)", Controller
32
- #
33
- # * routes can define their own parameters, for their own logic:
34
- #
35
- # route "/path/:required_paramater/:required_paramater{with_format}/(:optional_paramater)/(:optional){with_format}"
36
- #
37
- # * routes can define optional or required routes with regular expressions in them:
38
- #
39
- # route "(:locale){en|ru}/path"
40
- #
41
- # * routes which use the special '/' charecter within a parameter's format, must escape this charecter using the '\' charecter. **Notice the single quotes** in the following example:
42
- #
43
- # route '(:math){[\d\+\-\*\^\%\.\/]}'
44
- #
45
- # * or, with double quotes:
46
- #
47
- # route "(:math){[\\d\\+\\-\\*\\^\\%\\.\\/]}"
48
- #
49
- # magic routes make for difficult debugging - the smarter the routes, the more difficult the debugging.
50
- # use with care and avoid complex routes when possible. RESTful routes are recommended when possible.
51
- # JSON serving apps are advised to use required parameters and empty sections indicating missing required parameters (i.e. /path///foo/bar///).
52
- #
53
- def route(path, controller = nil, &block)
54
- Plezi.route(path, controller, &block)
55
- end
56
-
57
- # adds a route to the all the existing servers and hosts.
58
- #
59
- # accepts same options as route.
60
- def shared_route(path, controller = nil, &block)
61
- Plezi.shared_route(path, controller, &block)
62
- end
63
-
64
- # defines a method with a special name, such as "humens.txt".
65
- #
66
- # this could be used in controller classes, to define special routes which might defy
67
- # normal Ruby naming conventions, such as "/welcome-home", "/play!", etc'
68
- #
69
- # could also be used to define methods with special formatting, such as "humans.txt",
70
- # until a more refined way to deal with formatting will be implemented.
71
- def def_special_method name, obj=self, &block
72
- obj.instance_exec { define_method name.to_s.to_sym, &block }
73
- end
74
-
75
-
76
- # sets information to be used when restarting
77
- $PL_SCRIPT = $0
78
- $PL_ARGV = $*.dup
79
-
80
- # restarts the Plezi app with the same arguments as when it was started.
81
- #
82
- # EXPERIMENTAL
83
- def restart_plezi_app
84
- exec "/usr/bin/env ruby #{$PL_SCRIPT} #{$PL_ARGV.join ' '}"
85
- end
86
-
87
- # sets to start the services once dsl script is finished loading.
88
- at_exit do
89
- undef listen
90
- undef host
91
- undef route
92
- undef shared_route
93
- end
94
- end
@@ -1,65 +0,0 @@
1
-
2
- module Plezi
3
-
4
- module Base
5
- module AutoRedis
6
- @redis_locker ||= Mutex.new
7
- @redis = @redis_sub_thread = nil
8
- module_function
9
- def inner_init_redis
10
- return false unless ENV['PL_REDIS_URL'] && defined?(::Redis)
11
- @redis_locker.synchronize do
12
- return @redis if (@redis_sub_thread && @redis_sub_thread.alive?) && @redis # repeat the test once syncing is done.
13
- @redis.quit if @redis
14
- @redis = ::Redis.new(url: ENV['PL_REDIS_URL'])
15
- raise "Redis connction failed for: #{ENV['PL_REDIS_URL']}" unless @redis
16
- @redis_sub_thread = Thread.new do
17
- begin
18
- ::Redis.new(url: ENV['PL_REDIS_URL']).subscribe(Plezi::Settings.redis_channel_name, Plezi::Settings.uuid) do |on|
19
- on.message do |channel, msg|
20
- ::Plezi::Base::WSObject.forward_message ::Plezi::Base::WSObject.translate_message(msg)
21
- end
22
- end
23
- rescue => e
24
- Iodine.error e
25
- retry
26
- end
27
- end
28
- @redis
29
- end
30
- end
31
- def get_redis
32
- return @redis if (@redis_sub_thread && @redis_sub_thread.alive?) && @redis
33
- inner_init_redis
34
- end
35
- def away? server
36
- return true unless get_redis
37
- @redis.pubsub('CHANNELS', server).empty?
38
- end
39
- end
40
- end
41
-
42
- module_function
43
-
44
- # Reviews the Redis connection, sets it up if it's missing and returns the Redis connection.
45
- #
46
- # A Redis connection will be automatically created if the `ENV['PL_REDIS_URL']` is set.
47
- # for example:
48
- # ENV['PL_REDIS_URL'] = ENV['REDISCLOUD_URL']`
49
- # or
50
- # ENV['PL_REDIS_URL'] = "redis://:password@my.host:6379/0"
51
- #
52
- # Accepts an optional block that will receive the Redis connection object. i.e.
53
- #
54
- # Plezi.redis {|r| r.connected? }
55
- #
56
- # Returns the Redis object or the block's returned value (if a block is provided).
57
- def redis
58
- if r = Plezi::Base::AutoRedis.get_redis
59
- return (block_given? ? yield(r) : r)
60
- end
61
- false
62
- end
63
- alias :redis_connection :redis
64
- end
65
-
@@ -1,141 +0,0 @@
1
- module Plezi
2
- module Base
3
-
4
- class ExtentionManager
5
- def initialize
6
- @render_library = {}
7
- @locker = Mutex.new
8
- end
9
- # Registers a rendering extention.
10
- #
11
- # Slim, Haml and ERB are registered by default.
12
- #
13
- # extention:: a Symbol or String representing the extention of the file to be rendered. i.e. 'slim', 'md', 'erb', etc'
14
- # handler :: a Proc or other object that answers to call(filename, context, &block) and returnes the rendered string. The block accepted by the handler is for chaining rendered actions (allowing for `yield` within templates) and the context is the object within which the rendering should be performed (if `binding` handling is supported by the engine).
15
- #
16
- # If a block is passed to the `register_hook` method with no handler defined, it will act as the handler.
17
- def register extention, handler = nil, &block
18
- handler ||= block
19
- raise "Handler or block required." unless handler
20
- @locker.synchronize { @render_library[extention.to_s] = handler }
21
- handler
22
- end
23
- def review extention
24
- @locker.synchronize { @render_library[extention.to_s] }
25
- end
26
- # Removes a registered render extention
27
- def remove extention
28
- @locker.synchronize { @render_library.delete extention.to_s }
29
- end
30
- def each &block
31
- block_given? ? @render_library.each(&block) : @render_library.each
32
- end
33
-
34
-
35
- def render base_filename, context = ( Object.new.instance_eval { binding } ), &block
36
- @render_library.each {|ext, handler| f = "#{base_filename}.#{ext}".freeze ; return handler.call(f, context, &block) if File.exist?(f) }
37
- false
38
- end
39
-
40
- end
41
-
42
- module SASSExt
43
- module_function
44
- SASS_OPTIONS = { style: (ENV['SASS_STYLE'] || ((ENV['ENV'] || ENV['RACK_ENV']) == 'production' ? :compressed : :nested )) }
45
-
46
- def call filename, context, &block
47
- return false unless defined? ::Sass
48
- SASS_OPTIONS[:cache_store] ||= Sass::CacheStores::Memory.new
49
- # review mtime and render sass if necessary
50
- if refresh_sass?(filename)
51
- eng = Sass::Engine.for_file(filename, SASS_OPTIONS)
52
- Plezi.cache_data filename, eng.dependencies
53
- css, map = eng.render_with_sourcemap("#{File.basename(filename, '.*'.freeze)}.map".freeze)
54
- Plezi.cache_data filename.sub(/\.s[ac]ss$/, '.map'.freeze), map.to_json( css_uri: File.basename(filename, '.*'.freeze) )
55
- Plezi.cache_data "#{filename}.css", css
56
- return css
57
- end
58
- Plezi.get_cached("#{filename}.css")
59
- end
60
-
61
- def refresh_sass? sass
62
- return true if Plezi.cache_needs_update?(sass)
63
- # return false unless Plezi.allow_cache_update? # no meaningful performance boost.
64
- mt = Plezi.file_mtime(sass)
65
- Plezi.get_cached(sass).each {|e| return true if File.exists?(e.options[:filename]) && (File.mtime(e.options[:filename]) > mt)} # fn = File.join( e.options[:load_paths][0].root, e.options[:filename])
66
- false
67
- end
68
- end
69
- end
70
-
71
- # asset rendering extentions.
72
- module AssetManager
73
- @render_library = {}
74
- @locker = Mutex.new
75
-
76
- module_function
77
- # Registers a rendering extention for a specific asset type (js, css, etc').
78
- #
79
- # type:: the type of
80
- # extention:: a Symbol or String representing the extention of the file to be rendered. i.e. 'scss', 'sass', 'coffee', etc'
81
- # handler :: a Proc or other object that answers to call(filename, context, &block) and returnes the rendered string. The block accepted by the handler is for chaining rendered actions (allowing for `yield` within templates) and the context is a Binding object which is offered to the rendering (if `binding` handling is supported by the engine).
82
- #
83
- # handlers are expected to manage caching for their data. The {Plezi::Cache} module is available for this task,
84
- # but it should be noted that Plezi might cache data in that same system and conflicts might occure if the final filename isn't used for the caching (including the handler-type extention, i.e. 'coffee', slim' or 'erb').
85
- #
86
- # If a block is passed to the `register_hook` method with no handler defined, it will act as the handler.
87
- def register type, extention, handler = nil, &block
88
- raise "Type required." unless type
89
- handler ||= block
90
- raise "Handler or block required." unless handler
91
- @locker.synchronize { (@render_library[type.to_s] ||= ::Plezi::Base::ExtentionManager.new).register extention, handler }
92
- handler
93
- end
94
- # Removes a registered render extention
95
- def remove type, extention
96
- @locker.synchronize { (@render_library[type.to_s] ||= ::Plezi::Base::ExtentionManager.new).remove extention.to_s }
97
- end
98
- # returns an array with all the registered extentions
99
- def all_extentions
100
- out = []
101
- @render_library.each {|t, l| l.each {|e, h| out << e } }
102
- out.uniq!
103
- out
104
- end
105
-
106
-
107
- def render base_filename, context = ( Object.new.instance_eval { binding } ), &block
108
- handlers = @render_library[File.extname(base_filename)[1..-1]]
109
- handlers.each {|ext, handler| f = "#{base_filename}.#{ext}".freeze ; return handler.call(f, context, &block) if File.exists?(f) } if handlers
110
- false
111
- end
112
- end
113
-
114
- # Render Managment
115
- Renderer = ::Plezi::Base::ExtentionManager.new
116
-
117
- Renderer.register :erb do |filename, context, &block|
118
- next unless defined? ::ERB
119
- ( Plezi.cache_needs_update?(filename) ? Plezi.cache_data( filename, ( ERB.new( Plezi::Base::Helpers.try_utf8! IO.binread(filename) ) ) ) : (Plezi.get_cached filename) ).result((context) , &block)
120
- end
121
- Renderer.register :slim do |filename, context, &block|
122
- next unless defined? ::Slim
123
- ( Plezi.cache_needs_update?(filename) ? Plezi.cache_data( filename, ( Slim::Template.new() { Plezi::Base::Helpers.try_utf8! IO.binread(filename) } ) ) : (Plezi.get_cached filename) ).render(context.receiver, &block)
124
- end
125
- Renderer.register :haml do |filename, context, &block|
126
- next unless defined? ::Haml
127
- ( Plezi.cache_needs_update?(filename) ? Plezi.cache_data( filename, ( Haml::Engine.new( Plezi::Base::Helpers.try_utf8! IO.binread(filename) ) ) ) : (Plezi.get_cached filename) ).render(context.receiver, &block)
128
- end
129
-
130
- # JavaScript asset rendering
131
- AssetManager.register :js, :erb, Renderer.review(:erb)
132
- AssetManager.register :js, :coffee do |filename, context, &block|
133
- next unless defined? ::CoffeeScript
134
- ( Plezi.cache_needs_update?(filename) ? Plezi.cache_data( filename, CoffeeScript.compile(Plezi::Base::Helpers.try_utf8!(IO.binread(filename))) ) : (Plezi.get_cached filename) )
135
- end
136
-
137
- # CSS asset rendering
138
- AssetManager.register :css, :erb, Renderer.review(:erb)
139
- AssetManager.register :css, :scss, ::Plezi::Base::SASSExt
140
- AssetManager.register :css, :sass, ::Plezi::Base::SASSExt
141
- end
@@ -1,52 +0,0 @@
1
-
2
- module Plezi
3
-
4
- # This module allows you to set some of the Plezi framework's settings.
5
- module Settings
6
-
7
- module_function
8
-
9
- # Sets the Redis Channel Name.
10
- def redis_channel_name=val
11
- return false unless defined? Redis
12
- raise "Can't change channel name after Redis subscription had been initiated." if @redis
13
- @redis_channel_name = val
14
- end
15
- # Returns the Redis Channel Name used by this app.
16
- # @return [String]
17
- def redis_channel_name
18
- @redis_channel_name ||= "#{File.basename($0, '.*')}_redis_channel"
19
- end
20
-
21
- # Sets the message byte size limit for a Websocket message. Defaults to 0 (no limit)
22
- #
23
- # Although memory will be allocated for the latest TCP/IP frame,
24
- # this allows the websocket to disconnect if the incoming expected message size exceeds the allowed maximum size.
25
- #
26
- # If the sessage size limit is exceeded, the disconnection will be immidiate as an attack will be assumed. The protocol's normal disconnect sequesnce will be discarded.
27
- def ws_message_size_limit=val
28
- Iodine::Http::Websockets.message_size_limit = val
29
- end
30
- # Gets the message byte size limit for a Websocket message. Defaults to 0 (no limit)
31
- def ws_message_size_limit
32
- Iodine::Http::Websockets.message_size_limit
33
- end
34
-
35
- # This Server's UUID, for Redis and unicasting identification.
36
- def uuid
37
- @uuid ||= SecureRandom.uuid
38
- end
39
-
40
-
41
- # # # The following was discarded because benchmarks show the difference is negligible
42
- # # Get the cache refresh directive for the {#cache_needs_update?} implementation. Defaults to ENV['ENV'] != 'production'
43
- # def allow_cache_update?
44
- # Plezi.allow_cache_update?
45
- # end
46
- # # Set the cache refresh directive for the {#cache_needs_update?} implementation. Defaults to ENV['ENV'] != 'production'
47
- # def allow_cache_update= val
48
- # Plezi.allow_cache_update = val
49
- # end
50
- # # **Update**: up until now, Plezi would allow refresh any cached assets ot templated when they are edited. This file review is usually a waste of resources after deployment, since the files never get updated in production environments. Plezi now supports a two new settings options: `Plezi.allow_cache_update?` and `Plezi.allow_cache_update=` which will dictate if file review should be performed after caching. The default is now set to AVOID file reviews for production environments (`ENV['ENV'] || ENV['RACK_ENV'] != 'production'`).
51
- end
52
- end
@@ -1,106 +0,0 @@
1
- module Plezi
2
- module Base
3
-
4
- # the methods defined in this module will be injected into the Controller's Core class (inherited from the controller).
5
- module ControllerCore
6
- # @!parse include Plezi::Base::WSObject
7
- # @!parse include InstanceMethods
8
- # @!parse extend ClassMethods
9
-
10
- def self.included base
11
- base.send :include, Plezi::Base::WSObject
12
- base.send :include, InstanceMethods
13
- base.extend ClassMethods
14
- end
15
-
16
- module InstanceMethods
17
- public
18
-
19
- def initialize request, response
20
- @request = request
21
- @params = request.params
22
- @flash = response.flash
23
- @host_params = request[:host_settings]
24
- @response = response
25
- @cookies = request.cookies
26
- # # \@response["content-type"] ||= ::Plezi.default_content_type
27
- super()
28
- end
29
-
30
-
31
- # WebSockets.
32
- #
33
- # this method handles the protocol and handler transition between the HTTP connection
34
- # (with a protocol instance of HTTPProtocol and a handler instance of HTTPRouter)
35
- # and the WebSockets connection
36
- # (with a protocol instance of WSProtocol and an instance of the Controller class set as a handler)
37
- def pre_connect
38
- # make sure this is a websocket controller
39
- return false unless self.class.has_super_method?(:on_message) || self.class.superclass.instance_variable_get(:@auto_dispatch)
40
- # call the controller's original method, if exists, and check connection.
41
- return false if (defined?(super) && !super)
42
- # finish if the response was sent
43
- return false if response.headers_sent?
44
- # make sure that the session object is available for websocket connections
45
- session
46
- # make sure that rendering uses JSON for websocket messages (unless already set)
47
- params[:format] ||= 'json'
48
- # complete handshake
49
- return self
50
- end
51
-
52
- # Websockets
53
- #
54
- # this method either forwards the on_message handling to the `on_message` callback, OR
55
- # auto-dispatches the messages by translating the JSON into a method call using the `event` keyword.
56
- def on_message data
57
- unless self.class.superclass.instance_variable_get(:@auto_dispatch)
58
- return super if defined? super
59
- return false
60
- end
61
- begin
62
- data = JSON.parse data
63
- return close unless data.is_a?(Hash)
64
- rescue
65
- return close
66
- end
67
- Plezi::Base::Helpers.make_hash_accept_symbols data
68
- ret = nil
69
- begin
70
- if data['_EID_'.freeze]
71
- write "{\"event\":\"_ack_\",\"_EID_\":#{data['_EID_'.freeze]}}"
72
- end
73
- if self.class.has_auto_dispatch_method?(data['event'.freeze] = data['event'.freeze].to_s.to_sym)
74
- ret = self.__send__(data['event'.freeze], data)
75
- else
76
- ret = (self.class.has_super_method?(:unknown) && ( unknown(data) || true)) || (self.class.has_super_method?(:unknown_event) && Iodine.warn('Auto-Dispatch API updated: use `unknown` instead of `unknown_event`') && ( unknown_event(data) || true)) || ({ event: :err, status: 404, result: "not found", request: data }.to_json)
77
- end
78
- rescue ArgumentError => e
79
- Iodine.error "Auto-Dispatch Error for event :#{data['event'.freeze]} - #{e.message}"
80
- end
81
- ret = ret.to_json if ret.is_a?(Hash)
82
- write(ret) if ret.is_a?(String)
83
- end
84
-
85
- # Inner Routing
86
- def _route_path_to_methods_and_set_the_response_
87
- #run :before filter
88
- return false if self.class.has_method?(:before) && self.before == false
89
- #check request is valid and call requested method
90
- ret = requested_method
91
- return false unless ret
92
- ret = self.__send__(ret)
93
- return false unless ret
94
- #run :after filter
95
- return false if self.class.has_method?(:after) && self.after == false
96
- # review returned type for adding String to response
97
- return ret
98
- end
99
-
100
- end
101
-
102
- module ClassMethods
103
- end
104
- end
105
- end
106
- end