plezi 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07be3dac0b13bbf73ca5e0890887e07f41714d04
4
- data.tar.gz: 12165bf821d681d1244fe4d66816acd60da1999e
3
+ metadata.gz: 46dea93c274cc8c463747a8d91e46c4af6852a86
4
+ data.tar.gz: 56b9726006f702548770d2ea7beebbec6564ad8c
5
5
  SHA512:
6
- metadata.gz: 7828a5c7a2b81270eedda66063937aa763bfcd363d1c3e20252bd8a781e54a789bae4533705f531087d5a6824a4388e6ea9d0785bf52e50a6a011d82ef986035
7
- data.tar.gz: 95c13086f6e6680ea23dad7e76c631a5428a683a330c1ab30bf481b336efbc427b190ccc090c6c5eb9f98f80ff441dadd9c0354d5c99a1af771a5ded4c87d07e
6
+ metadata.gz: 30312ea6a47f7e8d9dc53a5c8c552046da2c064bdab79f15699507e8bd8628a9ce0c9fc47ea31d19073e271ec9394082e5066f301f5115ffeb10dfe08a31e59f
7
+ data.tar.gz: 0d275aa94313f9fe2bfe87a29eba26f31ad37ec9226c27a982fb86522404576aa65810f5575f211f160ed7d561de5bf12af3ce694e82f153d03b6e1e4e9212ef
data/.gitignore CHANGED
@@ -20,3 +20,5 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+
24
+ .DS_Store
@@ -2,6 +2,14 @@
2
2
 
3
3
  ***
4
4
 
5
+ Change log v.0.14.2
6
+
7
+ **Dependencies**: updates to dependency version requirements.
8
+
9
+ **Performance**: minor performance updates, i.e.: in the router, moved a `case` statement from the live (app is running) stage to the prep (app is initializing) stage and saved the `call` method extraction result for faster middleware mode performance.
10
+
11
+ ***
12
+
5
13
  Change log v.0.14.1
6
14
 
7
15
  **Update**: update due to Iodine's 0.2.1 version and the deprecation of the `uuid` method (replaced by `conn_id` to minimize collisions).
data/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
  [![Inline docs](http://inch-ci.org/github/boazsegev/plezi.svg?branch=master)](http://www.rubydoc.info/github/boazsegev/plezi/master/frames)
5
5
  [![GitHub](https://img.shields.io/badge/GitHub-Open%20Source-blue.svg)](https://github.com/boazsegev/plezi)
6
6
 
7
- Are microservices on your mind? Do you dream of a an SPA that's easy to scale? Did you wonder if you could write a whole Websockets, RESTful AJAX back-end with just a few lines of code (application logic not included)?
7
+ Are microservices on your mind? Do you dream of a an SPA that's easy to scale? Did you wonder if you could write a whole Websockets, RESTful AJAX back-end with just a few lines of code (business logic not included)?
8
8
 
9
- Welcome to your new home with [plezi.io](http://www.plezi.io), the Ruby real-time framework that assumes the application's logic is *not* part of the web service.
9
+ Welcome to your new home with [plezi.io](http://www.plezi.io), the Ruby real-time framework that assumes the business logic is *seperate* from the web service logic.
10
10
 
11
- **NOTICE**: Plezi 0.14.0 (this branch) is NOT an update, it's a total rewrite. Features were _removed_ as well as altered. For example, Plezi is now a Rack framework, with the limitations of CGI design and the advantages of using existing middleware. API changes abound.
11
+ **NOTICE**: Plezi 0.14.x (this branch) is NOT an update, it's a total rewrite. Features were _removed_ as well as altered. For example, Plezi is now a Rack framework, with the limitations of CGI design and the advantages of using existing middleware. API changes abound.
12
12
 
13
13
  ## What does Plezi have to offer?
14
14
 
@@ -76,7 +76,7 @@ Or install it yourself as:
76
76
 
77
77
  ## Usage
78
78
 
79
- A new application:
79
+ A new application (default applications include a simple chatroom demo):
80
80
 
81
81
  $ plezi new app_name
82
82
 
@@ -96,17 +96,16 @@ Plezi.route '*', HelloWorld
96
96
  exit # <= if running from terminal, this will start the server
97
97
  ```
98
98
 
99
- ## Development
99
+ ## Documentation
100
100
 
101
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
+ Plezi is fairly well documented.
102
102
 
103
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
+ Documentation is available both in the forms of tutorials and explanations available on the [plezi.io website](http://www.plezi.io) as well as through [the YARD documentation](http://www.rubydoc.info/gems/plezi).
104
104
 
105
105
  ## Contributing
106
106
 
107
107
  Bug reports and pull requests are welcome on GitHub at https://github.com/boazsegev/plezi.
108
108
 
109
-
110
109
  ## License
111
110
 
112
111
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -33,7 +33,7 @@ module Plezi
33
33
  def app
34
34
  no_autostart
35
35
  puts "Running Plezi version: #{::Plezi::VERSION}"
36
- Plezi::Base::Router.method :call
36
+ Plezi::Base::Router.call_method
37
37
  end
38
38
 
39
39
  # Will add a route to the Plezi application.
@@ -166,25 +166,25 @@ module Plezi
166
166
  # puts "#{from} is available"
167
167
  # end
168
168
  #
169
- # Methods invoked using {unicast}, {broadcast} or {multicast} will quitely fail if the connection was lost, the requested method is undefined or the 'target' was invalid.
169
+ # Methods invoked using {unicast}, {broadcast} or {multicast} will quietly fail if the connection was lost, the requested method is undefined or the 'target' was invalid.
170
170
  def unicast(target, event_method, *args)
171
171
  ::Plezi::Base::MessageDispatch.unicast(id ? self : self.class, target, event_method, args)
172
172
  end
173
173
 
174
- # Invokes a method on every websocket connection that belongs to this Controller / Type. When using Iodine, the method is invoked asynchronously.
174
+ # Invokes a method on every websocket connection (except `self`) that belongs to this Controller / Type. When using Iodine, the method is invoked asynchronously.
175
175
  #
176
176
  # self.broadcast :my_method, "argument 1", "argument 2", 3
177
177
  #
178
- # Methods invoked using {unicast}, {broadcast} or {multicast} will quitely fail if the connection was lost, the requested method is undefined or the 'target' was invalid.
178
+ # Methods invoked using {unicast}, {broadcast} or {multicast} will quietly fail if the connection was lost, the requested method is undefined or the 'target' was invalid.
179
179
  def broadcast(event_method, *args)
180
180
  ::Plezi::Base::MessageDispatch.broadcast(id ? self : self.class, event_method, args)
181
181
  end
182
182
 
183
- # Invokes a method on every websocket connection in the application.
183
+ # Invokes a method on every websocket connection in the application (except `self`).
184
184
  #
185
185
  # self.multicast :my_method, "argument 1", "argument 2", 3
186
186
  #
187
- # Methods invoked using {unicast}, {broadcast} or {multicast} will quitely fail if the connection was lost, the requested method is undefined or the 'target' was invalid.
187
+ # Methods invoked using {unicast}, {broadcast} or {multicast} will quietly fail if the connection was lost, the requested method is undefined or the 'target' was invalid.
188
188
  def multicast(event_method, *args)
189
189
  ::Plezi::Base::MessageDispatch.multicast(id ? self : self.class, event_method, args)
190
190
  end
@@ -239,7 +239,7 @@ module Plezi
239
239
  # @private
240
240
  # This function is used internally by Plezi, do not call.
241
241
  def _pl_ad_httpreview(data)
242
- data = data.to_json if self.class._pl_is_ad? && data.is_a?(Hash)
242
+ return data.to_json if self.class._pl_is_ad? && data.is_a?(Hash)
243
243
  data
244
244
  end
245
245
 
@@ -22,7 +22,7 @@ module Plezi
22
22
  @controller = controller
23
23
  @param_names = []
24
24
  @origial = path.dup.freeze
25
- path2regex(m[2])
25
+ prep_params(m[2])
26
26
  self.class.qp
27
27
  case @controller
28
28
  when Class
@@ -36,17 +36,8 @@ module Plezi
36
36
 
37
37
  def call(request, response)
38
38
  return nil unless match(request.path_info, request)
39
- case @controller
40
- when Class
41
- c = @controller.new
42
- return c._pl_respond(request, response, Thread.current[@route_id])
43
- when Regexp
44
- params = Thread.current[@route_id]
45
- return nil unless controller =~ params[@param_names[0]]
46
- request.path_info = "/#{params.delete('*'.freeze).to_a.join '/'}"
47
- request.params.update params
48
- end
49
- nil
39
+ c = @controller.new
40
+ c._pl_respond(request, response, Thread.current[@route_id])
50
41
  end
51
42
 
52
43
  def fits_params(path, request)
@@ -70,7 +61,7 @@ module Plezi
70
61
  req_path.start_with?(@prefix) && fits_params(req_path, request)
71
62
  end
72
63
 
73
- def path2regex(postfix)
64
+ def prep_params(postfix)
74
65
  pfa = postfix.split '/'.freeze
75
66
  start = 0; stop = 0
76
67
  optional = false
@@ -108,5 +99,15 @@ module Plezi
108
99
  @qp ||= ::Rack::QueryParser.new(Hash, 65_536, 100)
109
100
  end
110
101
  end
102
+ class RouteRewrite < Route
103
+ def call(request, _response)
104
+ return nil unless match(request.path_info, request)
105
+ params = Thread.current[@route_id]
106
+ return nil unless controller =~ params[@param_names[0]]
107
+ request.path_info = "/#{params.delete('*'.freeze).to_a.join '/'}"
108
+ request.params.update params
109
+ nil
110
+ end
111
+ end
111
112
  end
112
113
  end
@@ -13,8 +13,10 @@ module Plezi
13
13
  module_function
14
14
 
15
15
  def new(app)
16
- puts 'Plezi as Middleware'
17
- @app = ((app == Plezi.app) ? nil : app)
16
+ if app && app != call_method
17
+ puts 'Plezi as Middleware'
18
+ @app = app
19
+ end
18
20
  Plezi.app
19
21
  end
20
22
 
@@ -36,6 +38,11 @@ module Plezi
36
38
  return response.finish
37
39
  end
38
40
 
41
+ # returns the `call` method. Used repeatedly in middleware mode and only once in application mode.
42
+ def call_method
43
+ @call_method ||= Plezi::Base::Router.method(:call)
44
+ end
45
+
39
46
  def route(path, controller)
40
47
  path = path.chomp('/'.freeze) unless path == '/'.freeze
41
48
  case controller
@@ -46,6 +53,7 @@ module Plezi
46
53
  path << '/*'.freeze unless path[-1] == '*'.freeze
47
54
  when Regexp
48
55
  path << '/*'.freeze unless path[-1] == '*'.freeze
56
+ return @routes << RouteRewrite.new(path, controller)
49
57
  end
50
58
  @routes << Route.new(path, controller)
51
59
  end
@@ -111,7 +119,7 @@ module Plezi
111
119
  while names.any? && params[name[0]]
112
120
  url << "/#{Rack::Utils.escape params[names.shift]}"
113
121
  end
114
- url = '/'.dup if url.empty?
122
+ url << '/'.freeze if url.empty?
115
123
  (url << '?') << Rack::Utils.build_nested_query(params) if params.any?
116
124
  url
117
125
  end
@@ -1,3 +1,3 @@
1
1
  module Plezi
2
- VERSION = '0.14.1'.freeze
2
+ VERSION = '0.14.2'.freeze
3
3
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_dependency 'iodine', '~> 0.2.1'
30
+ spec.add_dependency 'iodine', '~> 0.2', '>= 0.2.1'
31
31
  # spec.add_dependency 'redcarpet', '> 3.3.0'
32
32
  # spec.add_dependency 'slim', '> 3.0.0'
33
33
 
metadata CHANGED
@@ -1,20 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plezi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iodine
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 0.2.1
20
23
  type: :runtime
@@ -22,6 +25,9 @@ dependencies:
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.2'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 0.2.1
27
33
  - !ruby/object:Gem::Dependency