volt 0.9.3.pre6 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b47ed7510baf946cc2e65e7140be76022472b53
4
- data.tar.gz: cf681b804b8609987671fbf2626aaf399d39bec0
3
+ metadata.gz: 73635c7ae6b384dcaecd996e5c28bd99773c508d
4
+ data.tar.gz: 73703d5c1aff47c1ac8d7cd2fa514da542b1ee28
5
5
  SHA512:
6
- metadata.gz: ffcd6ef512a9b74b519b1b2ee294b8bef5d00075b8052ab6c4cee1375fac9662d2d2991024a469ccb7b8cf3c0e1d7388999dc6e5ff908f1b48a6705e8cef12df
7
- data.tar.gz: 811b21c5c24ee684593c7069aba0cd68fad6480b22486c0646f34e67f365b8ab7e0ef36857c0defba4030fc9be243745f27c9a2e8930a7ba6fe58a29afc3dad0
6
+ metadata.gz: 6faeee73ca44c142b8c88264dd89599d0351a6638b962d5b127aa54656bec4549caa22ba753a3b506a634bb212e3d1ef46175ec68b63c0e21f1bd58b6ebf009d
7
+ data.tar.gz: 83ef2428fe1b75ae3e7140f0acbb3008a31c22c0643adacabe27844ab3921457eca5bbf7e6370cf5328cd9b113cd3c205266424b82cb9cf267d4cfcb2813f8b0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Change Log
2
2
 
3
- ## 0.9.3.pre4
3
+ ## 0.9.3
4
+
4
5
  ### Added
5
6
  - Added validations block for conditional validation runs
6
7
  - you can now set the NO_FORKING=true ENV to prevent using the forking server in development.
@@ -17,6 +18,7 @@
17
18
  - You can now use .create to make a new item on a collection.
18
19
  - .inspect for models is now cleaner
19
20
  - Volt.current_user now works in HttpController's
21
+ - HttpControllers now can take promises in render.
20
22
  - You can now add your own middleware to the middleware stack. (see docs)
21
23
  - Added a threadpool for Tasks, and options to customize pool size in config/app.rb
22
24
  - Volt now handles Syntax errors much better, it will display an error message when your app does not compile, and can reload from that page when things change. (in development)
@@ -37,6 +39,7 @@
37
39
  - Each bindings now support promises.
38
40
  - Volt.fetch_current_user has been deprecated and Volt.current_user now returns a promise.
39
41
  - Volt.current_user? now returns a promise that yields a boolean
42
+ - Lots of bug fixes. (see github)
40
43
 
41
44
  ## 0.9.2
42
45
  ### Changed
@@ -54,7 +54,7 @@ class Generate < Thor
54
54
  method_option :name, type: :string, banner: 'The name of the HTTP Controller.'
55
55
  method_option :component, type: :string, default: 'main', banner: 'The component the http_controller should be created in.', required: false
56
56
  def http_controller(name, component = 'main')
57
- name = name.underscore.pluralize + '_controller' unless name =~ /_controller$/
57
+ name = name.underscore + '_controller' unless name =~ /_controller$/
58
58
 
59
59
  output_file = Dir.pwd + "/app/#{component}/controllers/server/#{name.underscore}.rb"
60
60
  spec_file = Dir.pwd + "/spec/app/#{component.underscore}/controllers/server/#{name}_spec.rb"
@@ -22,7 +22,7 @@ module Volt
22
22
  @params = Volt::Model.new(request.params.symbolize_keys.merge(params), persistor: Volt::Persistors::Params)
23
23
  end
24
24
 
25
- def perform(action)
25
+ def perform(action='index')
26
26
  filtered = run_actions(:before, action)
27
27
  send(action.to_sym) unless filtered
28
28
  run_actions(:after, action) unless filtered
@@ -55,6 +55,12 @@ module Volt
55
55
  end
56
56
 
57
57
  def respond
58
+ unless @response_status
59
+ # render was not called, show an error
60
+ @response_body = ['Error: render was not called in controller action']
61
+ @response_status = 500
62
+ end
63
+
58
64
  Rack::Response.new(response_body, response_status, response_headers)
59
65
  end
60
66
 
@@ -6,6 +6,8 @@ require 'volt/models/state_helpers'
6
6
  require 'volt/data_stores/data_store'
7
7
 
8
8
  module Volt
9
+ class RecordNotFoundException < Exception ; end
10
+
9
11
  class ArrayModel < ReactiveArray
10
12
  include ModelWrapper
11
13
  include ModelHelpers
@@ -114,12 +116,10 @@ module Volt
114
116
  model
115
117
  end.fail do |err|
116
118
  # remove from the collection because it failed to save on the server
117
- @array.delete(model)
119
+ # we don't need to call delete on the server.
120
+ index = @array.index(model)
121
+ delete_at(index, true)
118
122
 
119
- # TODO: the model might be in at a different position already, so we should use a full delete
120
- trigger_removed!(@array.size - 1)
121
- trigger_size_change!
122
- #
123
123
  # re-raise, err might not be an Error object, so we use a rejected promise to re-raise
124
124
  Promise.new.reject(err)
125
125
  end
@@ -161,6 +161,12 @@ module Volt
161
161
  end
162
162
  end
163
163
 
164
+ # Same as first, except it returns a promise (even on page collection), and
165
+ # it fails with a RecordNotFoundException if no result is found.
166
+ def first!
167
+ fail_not_found_if_nil(first)
168
+ end
169
+
164
170
  # Return the first item in the collection, or create one if one does not
165
171
  # exist yet.
166
172
  def first_or_create
@@ -256,7 +262,13 @@ module Volt
256
262
  end
257
263
 
258
264
  def to_json
259
- to_a.to_json
265
+ array = to_a
266
+
267
+ if array.is_a?(Promise)
268
+ array.then(&:to_json)
269
+ else
270
+ array.to_json
271
+ end
260
272
  end
261
273
 
262
274
 
@@ -284,6 +296,17 @@ module Volt
284
296
  model
285
297
  end
286
298
 
299
+ # Raise a RecordNotFoundException if the promise returns a nil.
300
+ def fail_not_found_if_nil(promise)
301
+ promise.then do |val|
302
+ if val
303
+ val
304
+ else
305
+ raise RecordNotFoundException.new
306
+ end
307
+ end
308
+ end
309
+
287
310
  # We need to setup the proxy methods below where they are defined.
288
311
  proxy_with_load :[], :size, :last, :reverse, :all, :to_a
289
312
 
@@ -122,7 +122,7 @@ module Volt
122
122
 
123
123
  alias_method :length, :size
124
124
 
125
- def delete_at(index)
125
+ def delete_at(index, skip_persistor=false)
126
126
  size = @array.size
127
127
  # Handle a negative index
128
128
  index = size + index if index < 0
@@ -143,7 +143,7 @@ module Volt
143
143
 
144
144
  trigger_size_change!
145
145
 
146
- @persistor.removed(model) if @persistor
146
+ @persistor.removed(model) if @persistor && !skip_persistor
147
147
 
148
148
  model
149
149
  end
@@ -30,12 +30,18 @@ module Volt
30
30
  renderer = self.class.renderers[renderer_name]
31
31
  to_render = content.delete(renderer_name)
32
32
  rendered = renderer[:proc].call(to_render)
33
+
34
+ # Unwrap a promise if we got one back
35
+ if rendered.is_a?(Promise)
36
+ rendered = rendered.sync
37
+ end
38
+
33
39
  return [rendered, content.merge(content_type: renderer[:content_type])]
34
40
  end
35
41
  end
36
42
 
37
43
  # If we couldn't find a renderer - just render an empty string
38
- ['', content_type: 'text/plain']
44
+ ["Error: render only supports #{self.class.renderers.keys.join(', ')}", content_type: 'text/plain']
39
45
  end
40
46
  end
41
47
  end
@@ -16,9 +16,11 @@ class QuietCommonLogger < Rack::CommonLogger
16
16
  ext = nil
17
17
  end
18
18
 
19
+ @logged = false
20
+
19
21
  body = BodyProxy.new(body) do
20
22
  # Don't log on ignored extensions
21
- unless @@ignore_extensions.include?(ext)
23
+ if !@@ignore_extensions.include?(ext) && !@logged
22
24
  log(env, status, header, began_at)
23
25
  end
24
26
  end
@@ -26,6 +28,7 @@ class QuietCommonLogger < Rack::CommonLogger
26
28
  # Because of web sockets, the initial request doesn't finish, so we
27
29
  # can just trigger it now.
28
30
  unless ext || path.start_with?('/channel')
31
+ @logged = true
29
32
  log(env, status, header, began_at)
30
33
  end
31
34
 
@@ -78,6 +78,11 @@ class Promise
78
78
  end
79
79
  end
80
80
 
81
+ # Forward to resolved value
82
+ def to_json(*args, &block)
83
+ self.then {|v| v.to_json(*args, &block) }
84
+ end
85
+
81
86
 
82
87
 
83
88
  # Waits for the promise to resolve (assuming it is blocking on
data/lib/volt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Volt
2
2
  module Version
3
- STRING = '0.9.3.pre6'
3
+ STRING = '0.9.3'
4
4
  end
5
5
  end
@@ -17,9 +17,9 @@ describe Volt::HttpResponseRenderer do
17
17
  expect(additional_headers[:content_type]).to eq('text/plain')
18
18
  end
19
19
 
20
- it 'should default to text/plain if no suitable renderer could be found' do
20
+ it 'should give renderer error if no suitable renderer could be found' do
21
21
  body, additional_headers = renderer.render(some: 'text')
22
- expect(body).to eq('')
22
+ expect(body).to eq('Error: render only supports json, text')
23
23
  expect(additional_headers[:content_type]).to eq('text/plain')
24
24
  end
25
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3.pre6
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
@@ -828,9 +828,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
828
828
  version: '2.1'
829
829
  required_rubygems_version: !ruby/object:Gem::Requirement
830
830
  requirements:
831
- - - ">"
831
+ - - ">="
832
832
  - !ruby/object:Gem::Version
833
- version: 1.3.1
833
+ version: '0'
834
834
  requirements: []
835
835
  rubyforge_project:
836
836
  rubygems_version: 2.4.5