wedge 0.1.20 → 0.1.21

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: 164e8c7334f161e44b6a9770b12ed5a8e5d6be0d
4
- data.tar.gz: b7db45c79f2c49cc7238742a66623ddd141bd2ff
3
+ metadata.gz: a265e4fa793983ef66765457cb162508d1c1a5a4
4
+ data.tar.gz: e0da79dfdac85063881710ecd1266d8d8a5129c2
5
5
  SHA512:
6
- metadata.gz: 5e478d89243b932942747ed53637b06d2e821475cf7d167b3d7efb109dfe1290a791a44db4fa9bfabed2ff00791cad6195bef947c07ceb6dfb8f500d62dbf7ef
7
- data.tar.gz: e81c3747ba066a1365ee620dcd703a7a54a6ce39cce2b37b24bd04eaece714b0cf55d688fa4319893b1fa432fcf72cbcb033379f74534c46f9cce3285298ca7a
6
+ metadata.gz: 03b94e2207a5dc52b91187cb66e89dbff0ce902ffb33f3f7558e4614c9d94635f3260d7c940b12e60977b53b076f01bbca7d2eeb1c01c602005997497df59f58
7
+ data.tar.gz: 9d80870d1c844e4753daa99e198ca1c80bb58d1649485926b976d4effc7609af976c6868e8553485a0851eb1ba6d4b9897e54961437a2afa0b2a30c1565ac5d5
@@ -2,11 +2,7 @@ class Roda
2
2
  module RodaPlugins
3
3
  class WedgePlugin
4
4
  def self.configure(app, opts = false, &block)
5
- if !opts || !opts.delete(:disable_middleware)
6
- app.use Wedge::Middleware, opts || block
7
- else
8
- opts.each { |k, v| Wedge.config.send "#{k}=", v }
9
- end
5
+ app.use Wedge::Middleware, opts || block, true
10
6
  end
11
7
 
12
8
  module ClassMethods
@@ -28,7 +24,7 @@ class Roda
28
24
  module RequestMethods
29
25
  def wedge_assets
30
26
  on Wedge.assets_url_regex do
31
- run @@__wedge_middleware__ ||= Wedge::Middleware.scope!(scope).new
27
+ run Wedge::Middleware.scope!(scope)
32
28
  end
33
29
  end
34
30
  end
@@ -1,29 +1,43 @@
1
1
  class Wedge
2
2
  class Middleware
3
- def initialize(app = false, settings = {}, scope = false)
4
- @app = app
5
- @scope = scope || self.class.scope
6
- @opal = Wedge::Opal::Server.new { |s|
7
- s.prefix = Wedge.config.assets_url
8
- s.debug = Wedge.config.debug
9
- s.append_path "#{Dir.pwd}/#{Wedge.config.app_dir}"
10
- }
11
-
12
- case settings
13
- when Proc
14
- Wedge.config.instance_eval &settings
15
- else
16
- settings.each { |k, v| Wedge.config.send "#{k}=", v }
3
+ attr_reader :skip_call
4
+
5
+ def initialize(app = false, settings = false, skip_call = false)
6
+ if settings
7
+ case settings
8
+ when Proc
9
+ Wedge.config.instance_eval &settings
10
+ else
11
+ settings.each { |k, v| Wedge.config.send "#{k}=", v }
12
+ end
13
+
14
+ @opal = { server: Wedge::Opal::Server.new { |s|
15
+ s.prefix = Wedge.config.assets_url
16
+ s.debug = Wedge.config.debug
17
+ s.append_path "#{Dir.pwd}/#{Wedge.config.app_dir}"
18
+ }}
19
+
20
+ if Wedge.config.debug
21
+ @opal[:sprockets] = @opal[:server].sprockets
22
+ @opal[:maps_prefix] = "#{Wedge.config.assets_url}/__OPAL_SOURCE_MAPS__"
23
+ @opal[:maps_app] = Opal::SourceMapServer.new @opal[:sprockets], @opal[:maps_prefix]
24
+
25
+ Wedge::Opal::Sprockets::SourceMapHeaderPatch.inject! @opal[:maps_prefix]
26
+ end
17
27
  end
28
+
29
+ @app = app
30
+ @scope = self.class.scope
31
+ @skip_call = skip_call
18
32
  end
19
33
 
20
34
  def call(env)
21
- responder = Responder.new(@app, @opal, @scope, env)
35
+ responder = Responder.new(@app, @opal, @scope, @skip_call, env)
22
36
  responder.respond
23
37
  end
24
38
 
25
39
  class << self
26
- attr_accessor :scope
40
+ attr_accessor :scope, :skip_call
27
41
 
28
42
  def scope! scope
29
43
  klass = Class.new(self)
@@ -37,19 +51,22 @@ class Wedge
37
51
  end
38
52
 
39
53
  class Responder
40
- attr_reader :opal, :scope
54
+ attr_reader :opal, :scope, :skip_call
41
55
  attr_accessor :app, :env, :wedge_path, :extension
42
56
 
43
- def initialize(app, opal, scope, env)
44
- @app = app; @opal = opal; @scope = (scope || self); @env = env
57
+ def initialize(app, opal, scope, skip_call, env)
58
+ @app = app; @opal = opal; @scope = (scope || self); @skip_call = skip_call; @env = env
45
59
  end
46
60
 
47
61
  def respond
48
62
  if path =~ Wedge.assets_url_regex
49
63
  @wedge_path, @extension = $1, $2
50
- body, headers, status = [], {}, 200
51
64
 
52
65
  if extension == 'call'
66
+ return response.finish if skip_call
67
+
68
+ body, headers, status = [], {}, 200
69
+
53
70
  body_data = request.body.read
54
71
  data = request.params
55
72
 
@@ -92,7 +109,17 @@ class Wedge
92
109
 
93
110
  [status, headers, body]
94
111
  else
95
- @opal.call env
112
+ if Wedge.config.debug
113
+ if path[@opal[:maps_prefix]]
114
+ @opal[:maps_app].call env
115
+ else
116
+ e = env.deep_dup
117
+ e['PATH_INFO'] = env['PATH_INFO'].sub "#{Wedge.config.assets_url}/", ''
118
+ @opal[:sprockets].call e
119
+ end
120
+ else
121
+ @opal[:server].call env
122
+ end
96
123
  end
97
124
  else
98
125
  response.finish
@@ -171,7 +171,7 @@ class Wedge
171
171
  else
172
172
  # issue: OPAL is not using the alias method original_attr_reader
173
173
  # correctly. It's still somehow getting in here when called below.
174
- next if %w'_atts _options'.include? att.to_s
174
+ next if %w'_atts _options _atts_keys'.include? att.to_s
175
175
  ###################################################################
176
176
 
177
177
  # set empty options if need be
@@ -205,7 +205,8 @@ class Wedge
205
205
  alias alias_model model_alias
206
206
  end
207
207
 
208
- original_attr_reader :_atts, :_options
208
+ original_attr_reader :_atts, :_atts_keys, :_options
209
+
209
210
 
210
211
  # Initialize with a hash of attributes and values.
211
212
  # Extra attributes are discarded.
@@ -245,6 +246,7 @@ class Wedge
245
246
  atts.each do |key, val|
246
247
  # grab the original key if alias is given
247
248
  key = _aliases.invert[key] || key
249
+ (@_atts_keys ||= []) << key
248
250
 
249
251
  next if (_accessor_options[key] || {})[:form]
250
252
 
@@ -256,6 +258,18 @@ class Wedge
256
258
  end
257
259
  end
258
260
 
261
+ def _with_atts
262
+ _accessor_options[:with_atts] || []
263
+ end
264
+
265
+ def _without_atts
266
+ _accessor_options[:without_atts] || []
267
+ end
268
+
269
+ def _keys
270
+ (_atts_keys + _with_atts).reject { |k| _without_atts.include? k }
271
+ end
272
+
259
273
  def _accessors
260
274
  @_accessors ||= (self.class._accessors || IndifferentHash.new).deep_dup
261
275
  end
@@ -286,7 +300,7 @@ class Wedge
286
300
  _options[:_attributes] = true
287
301
  _options[:_model_attributes] = for_model
288
302
 
289
- _accessors.each do |att|
303
+ _keys.each do |att|
290
304
  opts = _accessor_options[att]
291
305
  if _atts.can_read?(att) && (!opts[:hidden] || opts[:hidden].is_a?(Proc) && !self.instance_exec(&opts[:hidden]))
292
306
  is_form = opts[:form]
@@ -102,7 +102,7 @@ class Wedge
102
102
  when :not_equal
103
103
  'Password does not match.'
104
104
  else
105
- !error[/\s/] ? error.to_s.gsub(/_/, ' ').titleize : error
105
+ !error.to_s[/\s/] ? error.to_s.gsub(/_/, ' ').titleize : error
106
106
  end
107
107
  end
108
108
  end
data/lib/wedge/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Wedge
2
- VERSION = '0.1.20'
2
+ VERSION = '0.1.21'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wedge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj