plezi 0.12.15 → 0.12.16

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: 1e2ced994d1b21af157a084e747c60c2fd113a5c
4
- data.tar.gz: 6828e742abc6eb612cf70bfbe0c6f2f6da1cac1c
3
+ metadata.gz: 6f6fba282cfa6309e0cccf3aff5da8e19de6fc5e
4
+ data.tar.gz: 9aa0efac03e405a8d4db93455d56b51ea328c956
5
5
  SHA512:
6
- metadata.gz: d7f1d3f579ae87afdf56028e80e093c00ae1f9bd01f155e424c71cb2d846cf418f109c82ee559d21454836345ebe219d614a6af0f11d94e81665fee40856e203
7
- data.tar.gz: 23a7279397df8ea1326bfe2da342b5c9c3ab5f85bb3970aae34bbc6c265e01b34392e292a2638e5b48596d720af2a1eb58ae588c624d63324b357c56c01b676f
6
+ metadata.gz: f447f812e27e63bd503c8ed4d945cd7202f5a6e38524b248368730295407a7a49336af8b45bc618e4f13b1f1112df0e0b0a1c73f1c96c0a199abb7277f4701f0
7
+ data.tar.gz: ab4818fb422e3d0a275f8a73338d50e70d3d092b7776b6bab3a6c8373f86f9b186a85f58e9dc1ee2ef08cdc7a1249aec18189b9786abcf9164c739707bf8aeef
@@ -2,6 +2,14 @@
2
2
 
3
3
  ***
4
4
 
5
+ Change log v.0.12.16
6
+
7
+ **Fix**: fixed an issue with the `#url_for` method, which couldn't be used as a class method.
8
+
9
+ **Update**: a new and improved `#url_for` method (both for Controller class and instance). The instance class will attempt to preserve any re-write route paramerets, such as the `:locale` and `:format` parameters. The class method will do the same IF it receives the exiting request's `params` Hash as a second argument. `#url_for` is always a "best guess" and should be accurate for when guessing isn't super difficult.
10
+
11
+ ***
12
+
5
13
  Change log v.0.12.15
6
14
 
7
15
  **Fix**: fixed the Redis connection, which was failing after DB selection support was added.
data/bin/plezi CHANGED
@@ -3,6 +3,7 @@ $0="Plezi Builder"
3
3
  # count lines of code with: ^[ \t]*[\w\d\"\(\{\@\[\]\}\)\:\'\.\*\&]+.*$
4
4
 
5
5
  require 'irb'
6
+ require 'benchmark'
6
7
  require 'securerandom'
7
8
  require 'plezi/builders/builder'
8
9
  require 'plezi/builders/app_builder'
@@ -70,13 +71,10 @@ elsif ARGV[0] == 'server' || ARGV[0] == 'start' || ARGV[0] == 's'
70
71
  ARGV.shift
71
72
  load File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last) ) rescue load( File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last ) ) )
72
73
  elsif ARGV[0] == 'console' || ARGV[0] == 'c'
73
- NO_PLEZI_AUTO_START ||= true
74
74
  load File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last) ) rescue load( File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last) ) )
75
75
  ARGV.clear
76
- IRB.setup nil
77
- IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
78
- require 'irb/ext/multi-irb'
79
- IRB.irb nil, self
76
+ Iodine.protocol = nil
77
+ IRB.start
80
78
  else
81
79
  puts ""
82
80
  puts "Plezi fast web app starter.".pink
@@ -21,6 +21,7 @@ module Plezi
21
21
  app_tree["Gemfile"] ||= String.new
22
22
  app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n"
23
23
  app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
24
+ app_tree["rakefile"] ||= IO.read(File.join(@root,"resources" ,"rakefile")).sub('initialize.rb', "#{app_name}.rb")
24
25
  app_tree["templates"] ||= {}
25
26
  app_tree["templates"]["404.html.erb"] ||= IO.read(File.join(@root, "resources" ,"404.erb"))
26
27
  app_tree["templates"]["500.html.erb"] ||= IO.read(File.join(@root, "resources" ,"500.erb"))
@@ -79,7 +79,7 @@ module Plezi
79
79
  #
80
80
  def redirect_to url, options = {}
81
81
  return super() if defined? super
82
- url = full_url_for(url) unless url.is_a?(String) || url.nil?
82
+ url = full_url_for(url, params) unless url.is_a?(String) || url.nil?
83
83
  # redirect
84
84
  response.redirect_to url, options
85
85
  end
@@ -97,13 +97,15 @@ module Plezi
97
97
  #
98
98
  # * If you use the same controller in different routes, the first route will dictate the returned url's structure (cause by route priority).
99
99
  #
100
+ # * The route's host will be ignored. Even when using {#full_url_for}, the same host as the current request will be assumed. To change hosts, add the new host's address manualy, i.e.: `request.base_url.gsub('//www.', '//admin.') + UserController.url_for(user.id, params)
101
+ #
100
102
  # * Not all controllers support this method. Regexp controller paths and multi-path options will throw an exception.
101
103
  def url_for dest = nil
102
- self.class.url_for dest
104
+ self.class.url_for dest, params
103
105
  end
104
106
  # same as #url_for, but returns the full URL (protocol:port:://host/path?params=foo)
105
107
  def full_url_for dest
106
- "#{request.base_url}#{self.class.url_for(dest)}"
108
+ "#{request.base_url}#{self.class.url_for(dest, params)}"
107
109
  end
108
110
 
109
111
  # Send raw data to be saved as a file or viewed as an attachment. Browser should believe it had recieved a file.
@@ -229,9 +231,24 @@ module Plezi
229
231
  module ClassMethods
230
232
  public
231
233
 
232
- # This class method behaves the same way as the instance method #url_for. See the instance method's documentation for more details.
233
- def url_for dest
234
- get_pl_route.url_for dest
234
+ # This class method behaves the same way as the instance method #url_for, but accepts an added `params` Hash
235
+ # that will be used to infer any persistent re-write parameters (i.e. `:locale` or `:format`).
236
+ # See the instance method's documentation for more details.
237
+ def url_for dest, params={}
238
+ case dest
239
+ when :index, nil, false
240
+ dest = {}
241
+ when String
242
+ dest = {id: dest}
243
+ when Numeric, Symbol
244
+ dest = {id: dest}
245
+ when Hash
246
+ true
247
+ else
248
+ # convert dest.id and dest[:id] to their actual :id value.
249
+ dest = {id: (dest.id rescue false) || (raise TypeError, "Expecting a Symbol, Hash, String, Numeric or an object that answers to obj[:id] or obj.id") }
250
+ end
251
+ ::Plezi::Base::HTTPRouter.url_for self, dest, params
235
252
  end
236
253
 
237
254
  # resets the routing cache
@@ -241,20 +258,6 @@ module Plezi
241
258
 
242
259
  protected
243
260
 
244
- # Sets the HTTP route that is the owner of this controller.
245
- #
246
- # This is used by the Plezi framework internally and is supplied only for advanced purposes. It is better to avoid using this method.
247
- def set_pl_route route
248
- @pl_http_route = route
249
- end
250
-
251
- # Gets the HTTP route that is the owner of this controller.
252
- #
253
- # This is used to utilize the `url_for` method.
254
- def get_pl_route
255
- @pl_http_route
256
- end
257
-
258
261
  # a callback that resets the class router whenever a method (a potential route) is added
259
262
  def method_added(id)
260
263
  reset_routing_cache
@@ -91,6 +91,61 @@ module Plezi
91
91
  end
92
92
  end
93
93
 
94
+ # This method attempts to guess at the desired controller's URL, based on it's first path in order of route creation (ignoring host hierarchy).
95
+ #
96
+ # This will be usually used by the Controller's #url_for method to get the relative part of the url.
97
+ def url_for controller, dest, params = {}
98
+ raise TypeError, "Expecting destination parameter to be a Hash" unless dest.is_a?(Hash)
99
+ host = nil
100
+ @hosts.values.each do |h|
101
+ h.routes.each {|r| (host = h) && (controller = r.controller) && break if r.controller && r.controller.ancestors.include?(controller) }
102
+ break if host
103
+ end
104
+ raise "couldn't find Controller's route and host." unless host
105
+ url = []
106
+ dest = dest.dup
107
+ dest.default_proc = Plezi::Base::Helpers::HASH_SYM_PROC
108
+ host.routes.each do |r|
109
+ if r.controller == false
110
+ add = []
111
+ r.url_array.each do |sec|
112
+ next if sec == '*'
113
+ param_name = (::Plezi::Base::Route::REGEXP_OPTIONAL_PARAMS.match(sec) || ::Plezi::Base::Route::REGEXP_FORMATTED_OPTIONAL_PARAMS.match(sec) || ::Plezi::Base::Route::REGEXP_REQUIRED_PARAMS.match(sec) || ::Plezi::Base::Route::REGEXP_FORMATTED_REQUIRED_PARAMS.match(sec))
114
+ param_name = param_name[1].to_sym if param_name
115
+
116
+ if param_name && (dest[param_name] || params[param_name])
117
+ add << Plezi::Base::Helpers.encode_url(dest.delete(param_name) || params[param_name])
118
+ elsif !param_name
119
+ add << sec
120
+ else
121
+ add.clear
122
+ next
123
+ end
124
+ end if r.url_array
125
+ url.concat add
126
+ end
127
+ if r.controller == controller
128
+ raise NotImplementedError, "#url_for isn't implemented for this controller's route - could this be a Regexp based or special route?" unless r.url_array
129
+ r.url_array.each do |sec|
130
+ next if sec == '*'
131
+ param_name = (::Plezi::Base::Route::REGEXP_OPTIONAL_PARAMS.match(sec) || ::Plezi::Base::Route::REGEXP_FORMATTED_OPTIONAL_PARAMS.match(sec) || ::Plezi::Base::Route::REGEXP_REQUIRED_PARAMS.match(sec) || ::Plezi::Base::Route::REGEXP_FORMATTED_REQUIRED_PARAMS.match(sec))
132
+ param_name = param_name[1].to_sym if param_name
133
+ if param_name && dest[param_name]
134
+ url << Plezi::Base::Helpers.encode_url(dest.delete(param_name))
135
+ elsif !param_name
136
+ url << sec
137
+ elsif ::Plezi::Base::Route::REGEXP_REQUIRED_PARAMS === sec || ::Plezi::Base::Route::REGEXP_OPTIONAL_PARAMS === sec
138
+ url << ''.freeze
139
+ elsif ::Plezi::Base::Route::REGEXP_FORMATTED_REQUIRED_PARAMS === sec
140
+ raise ArgumentError, "URL can't be formatted becuse a required parameter (#{param_name.to_s}) isn't specified and it requires a special format (#{::Plezi::Base::Route::REGEXP_FORMATTED_REQUIRED_PARAMS.match(sec)[2]})."
141
+ end
142
+ end
143
+ return "/#{url.join '/'.freeze}#{"?#{dest.map {|k,v| "#{Plezi::Base::Helpers.encode_url k}=#{Plezi::Base::Helpers.encode_url v}" } .join('&'.freeze)}" if dest.any?}"
144
+ end
145
+ end
146
+ false
147
+ end
148
+
94
149
  protected
95
150
 
96
151
  def get_host host_name
@@ -9,6 +9,8 @@ module Plezi
9
9
  attr_reader :proc
10
10
  # the parameters for the router and service that were used to create the service, router and host.
11
11
  attr_reader :params
12
+ # an array containing the parts of the original url, if any. `false` for Regexp or non relevant routes.
13
+ attr_reader :url_array
12
14
 
13
15
  # lets the route answer the request. returns false if no response has been sent.
14
16
  def on_request request, response
@@ -75,80 +77,6 @@ module Plezi
75
77
  end
76
78
  end
77
79
 
78
- # # returns the url for THIS route (i.e. `url_for :index`)
79
- # #
80
- # # This will be usually used by the Controller's #url_for method to get the relative part of the url.
81
- # def url_for dest = :index
82
- # raise NotImplementedError, "#url_for isn't implemented for this router - could this be a Regexp based router?" unless @url_array
83
- # # convert dest.id and dest[:id] to their actual :id value.
84
- # dest = (dest.id rescue false) || (raise TypeError, "Expecting a Symbol, Hash, String, Numeric or an object that answers to obj[:id] or obj.id") unless !dest || dest.is_a?(Symbol) || dest.is_a?(String) || dest.is_a?(Numeric) || dest.is_a?(Hash)
85
- # url = '/'
86
- # case dest
87
- # when false, nil, '', :index
88
- # add = true
89
- # @url_array.each do |sec|
90
- # add = false unless sec[0] != :path
91
- # url << sec[1] if add
92
- # raise NotImplementedError, '#url_for(index) cannot be implementedfor this path.' if !add && sec[0] == :path
93
- # # todo: :multi_path
94
- # end
95
- # when Hash
96
- # when Symbol, String, Numeric
97
- # end
98
- # end
99
-
100
-
101
-
102
- # returns the url for THIS route (i.e. `url_for :index`)
103
- #
104
- # This will be usually used by the Controller's #url_for method to get the relative part of the url.
105
- def url_for dest = :index
106
- raise NotImplementedError, "#url_for isn't implemented for this router - could this be a Regexp based router?" unless @url_array
107
- case dest
108
- when :index, nil, false
109
- dest = {}
110
- when String
111
- dest = {id: dest.dup}
112
- when Numeric, Symbol
113
- dest = {id: dest}
114
- when Hash
115
- dest = dest.dup
116
- dest.each {|k,v| dest[k] = v.dup if v.is_a? String }
117
- else
118
- # convert dest.id and dest[:id] to their actual :id value.
119
- dest = {id: (dest.id rescue false) || (raise TypeError, "Expecting a Symbol, Hash, String, Numeric or an object that answers to obj[:id] or obj.id") }
120
- end
121
- dest.default_proc = Plezi::Base::Helpers::HASH_SYM_PROC
122
-
123
- url = '/'.dup
124
-
125
- @url_array.each do |sec|
126
- raise NotImplementedError, "#url_for isn't implemented for this router - Regexp multi-path routes are still being worked on... use a named parameter instead (i.e. '/foo/(:multi_route){route1|route2}/bar')" if REGEXP_FORMATTED_PATH === sec
127
-
128
- param_name = (REGEXP_OPTIONAL_PARAMS.match(sec) || REGEXP_FORMATTED_OPTIONAL_PARAMS.match(sec) || REGEXP_REQUIRED_PARAMS.match(sec) || REGEXP_FORMATTED_REQUIRED_PARAMS.match(sec))
129
- param_name = param_name[1].to_sym if param_name
130
-
131
- if param_name && dest[param_name]
132
- url << Plezi::Base::Helpers.encode_url(dest.delete(param_name))
133
- url << '/'.freeze
134
- elsif !param_name
135
- url << sec
136
- url << '/'.freeze
137
- elsif REGEXP_REQUIRED_PARAMS === sec || REGEXP_OPTIONAL_PARAMS === sec
138
- url << '/'.freeze
139
- elsif REGEXP_FORMATTED_REQUIRED_PARAMS === sec
140
- raise ArgumentError, "URL can't be formatted becuse a required parameter (#{param_name.to_s}) isn't specified and it requires a special format (#{REGEXP_FORMATTED_REQUIRED_PARAMS.match(sec)[2]})."
141
- end
142
- end
143
- unless dest.empty?
144
- add = '?'.freeze
145
- dest.each {|k, v| url << "#{add}#{Plezi::Base::Helpers.encode_url k}=#{Plezi::Base::Helpers.encode_url v}"; add = '&'.freeze}
146
- end
147
- url
148
-
149
- end
150
-
151
-
152
80
  # Used to check for routes formatted: /:paramater - required parameters
153
81
  REGEXP_REQUIRED_PARAMS = /^\:([^\(\)\{\}\:]*)$/
154
82
  # Used to check for routes formatted: /(:paramater) - optional parameters
@@ -279,7 +207,6 @@ module Plezi
279
207
  end
280
208
  Object.const_set(new_class_name, ret)
281
209
  Module.const_get(new_class_name).reset_routing_cache
282
- ret.instance_exec(container) {|r| set_pl_route r;}
283
210
  ret
284
211
  end
285
212
 
@@ -0,0 +1,19 @@
1
+ # Make sure the server doesn't start
2
+ Iodine.protocol = false
3
+
4
+
5
+ namespace :make do
6
+ # add ActiveRecord controller-model generator
7
+
8
+ # add Squel controller-model generator
9
+
10
+ end
11
+ # add console mode
12
+ desc "Same as `plezi c`: starts the application as a console, NOT a server."
13
+ task :console do
14
+ Kernel.exec "plezi c"
15
+ end
16
+ desc "Same as `rake console`: starts the application as a console, NOT a server."
17
+ task :c do
18
+ Kernel.exec "plezi c"
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Plezi
2
- VERSION = "0.12.15"
2
+ VERSION = "0.12.16"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "iodine", "~> 0.1.15"
21
+ spec.add_dependency "iodine", "~> 0.1.16"
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
 
@@ -1,8 +1,7 @@
1
1
  # load all application code and gems
2
2
  load ::File.expand_path(File.join("..", "initialize.rb"), __FILE__)
3
-
4
- # Make sure the server doesn't start
5
- Iodine.protocol = false
3
+ # set Plezi to rake mode and load it's tasks (if relevant).
4
+ require "plezi/rake"
6
5
 
7
6
  # create a default task
8
7
  desc "The default task will simply remind you to call 'rake -T'."
@@ -335,9 +335,9 @@ module PleziTestTasks
335
335
  end
336
336
  end
337
337
  def test_url_for
338
- test_url = "/some/path/test/my_url/ask/"
339
- puts " * simple #url_for test: #{RESULTS[URI.parse("http://localhost:3000" + test_url).read == test_url]}"
340
- test_url = "/some/another_path/my_url/ask/"
338
+ test_url = "/some/path/test/my_url/ask"
339
+ puts " * simple #url_for test: #{RESULTS[(URI.parse("http://localhost:3000" + test_url).read == test_url) || puts("Got path: #{URI.parse("http://localhost:3000" + test_url).read}")]}"
340
+ test_url = "/some/another_path/my_url/ask"
341
341
  puts " * missing arguments #url_for test: #{RESULTS[URI.parse("http://localhost:3000" + test_url).read == test_url]}"
342
342
 
343
343
  rescue => e
@@ -364,7 +364,7 @@ module PleziTestTasks
364
364
  end
365
365
  end
366
366
  ws2 = Iodine::Http::WebsocketClient.connect("ws://localhost:3000/") do |data|
367
- next unless @is_connected || !( (@is_connected = true) )
367
+ next unless @is_connected || !( ( @is_connected = true ) == true )
368
368
  if data == "unicast"
369
369
  puts " * Websocket unicast message test: #{RESULTS[false]}"
370
370
  unicast_test = :failed
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plezi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.15
4
+ version: 0.12.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iodine
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.15
19
+ version: 0.1.16
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.15
26
+ version: 0.1.16
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,7 @@ files:
100
100
  - lib/plezi/helpers/mime_types.rb
101
101
  - lib/plezi/oauth.rb
102
102
  - lib/plezi/oauth/auth_controller.rb
103
+ - lib/plezi/rake.rb
103
104
  - lib/plezi/version.rb
104
105
  - logo/dark.png
105
106
  - logo/light.png