ruby_native 0.10.12 → 0.10.14

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
  SHA256:
3
- metadata.gz: a0c3d95e45afd32971cc8dc042ae37411aae04748b7b49cde8e9b94c9bc60a15
4
- data.tar.gz: 047153c52db88fca1315f83ee8447509cc5ff28cb11abd802d9ad368a5864dff
3
+ metadata.gz: 7b83fa869135734b170e4b23a8ca46984c54ea5b830326af54003f1a9006830a
4
+ data.tar.gz: 84e8db6d56e06beb29933463939dfa970d90bc652f52e68bd0b5ad8f41dc273f
5
5
  SHA512:
6
- metadata.gz: 1fe808f45eeff4c420ce915bb53b1267f39e5139c0b9626e0e0d1ac2829e169136b8248f1665de5bfb88251617949c570b293475324b4b254582e535bef51b79
7
- data.tar.gz: 9ae961899223792d3936309e098dbd3caa3e4bc6f09b0877fa88029973a5d582807cab250bedc10577b8790f8b7e2a80c23e2601ea7207c76e2c2a68704a1c39
6
+ metadata.gz: c555bdb8ff38ae5a851b81a733aed0554949b1d15352de103f7c90415a56a2b8ce8a21acd5f1724e8b6ebd648ba1a875a9b03f86b1d150f451b53369c2fb23f5
7
+ data.tar.gz: 7de2e7778924c227c6501201af4a5d233c4b1000a99edc93f5074c824526ce248c7cd8d98fa3f963a9935deae69c92fa8f74cf920c3f1e731415545ff80f329a
@@ -4,10 +4,20 @@ module RubyNative
4
4
  skip_forgery_protection
5
5
 
6
6
  def create
7
- device = current_user.push_devices.find_or_initialize_by(token: params[:token])
7
+ device = ruby_native_user.push_devices.find_or_initialize_by(token: params[:token])
8
8
  device.update!(platform: params[:platform], name: params[:name])
9
9
  head :ok
10
10
  end
11
+
12
+ private
13
+
14
+ # Resolves the signed-in user via RubyNative.current_user_resolver, which is
15
+ # either a controller method name (Symbol) or a callable run in the
16
+ # controller. Defaults to `current_user`.
17
+ def ruby_native_user
18
+ resolver = RubyNative.current_user_resolver
19
+ resolver.respond_to?(:call) ? instance_exec(&resolver) : send(resolver)
20
+ end
11
21
  end
12
22
  end
13
23
  end
@@ -187,7 +187,8 @@ module RubyNative
187
187
  puts ""
188
188
  puts url
189
189
  puts ""
190
- puts "Scan the QR code or paste the URL into the Ruby Native Preview app."
190
+ puts "Scan the QR code or paste the URL into the Ruby Native app."
191
+ puts "Don't have it yet? Download it at https://rubynative.com/try/download"
191
192
  if @url
192
193
  puts "Keep this running and your Rails server reachable at #{@url}."
193
194
  else
@@ -120,9 +120,9 @@ module RubyNative
120
120
  if block
121
121
  menu = NavbarMenuBuilder.new(@context)
122
122
  @context.capture(menu, &block)
123
- @items << @context.tag.div(data: data) { menu.to_html }
123
+ add(@context.tag.div(data: data) { menu.to_html })
124
124
  else
125
- @items << @context.tag.div(data: data)
125
+ add(@context.tag.div(data: data))
126
126
  end
127
127
  end
128
128
 
@@ -136,7 +136,7 @@ module RubyNative
136
136
  data[:native_href] = href if href
137
137
  data[:native_click] = click if click
138
138
  data[:native_selected] = "" if selected
139
- @items << @context.tag.div(data: data)
139
+ add(@context.tag.div(data: data))
140
140
  end
141
141
 
142
142
  # Adds a native share button to the nav bar. Tapping it opens the
@@ -152,20 +152,32 @@ module RubyNative
152
152
  data[:native_icon] = resolved if resolved
153
153
  data[:native_position] = position.to_s
154
154
  data[:native_share_url] = url if url
155
- @items << @context.tag.div(data: data)
155
+ add(@context.tag.div(data: data))
156
156
  end
157
157
 
158
158
  def submit_button(title: "Save", click: "[type='submit']")
159
- @items << @context.tag.div(data: {
159
+ add(@context.tag.div(data: {
160
160
  native_submit_button: "",
161
161
  native_title: title,
162
162
  native_click: click
163
- })
163
+ }))
164
164
  end
165
165
 
166
166
  def to_html
167
167
  @context.safe_join(@items)
168
168
  end
169
+
170
+ private
171
+
172
+ # Collects a signal element and returns a blank, html-safe string. That
173
+ # lets the builder read naturally with `<%=` in ERB (`<%= navbar.button %>`)
174
+ # without emitting anything, since the nav bar renders from the collected
175
+ # items in `to_html`, not from these return values. Silent `<% %>` tags
176
+ # keep working too.
177
+ def add(item)
178
+ @items << item
179
+ ActiveSupport::SafeBuffer.new
180
+ end
169
181
  end
170
182
 
171
183
  class NavbarMenuBuilder
@@ -181,7 +193,7 @@ module RubyNative
181
193
  data[:native_click] = click if click
182
194
  data[:native_icon] = resolved if resolved
183
195
  data[:native_selected] = "" if selected
184
- @items << @context.tag.div(data: data)
196
+ add(@context.tag.div(data: data))
185
197
  end
186
198
 
187
199
  # Adds a share entry to a navbar button's dropdown menu. Selecting it
@@ -194,12 +206,21 @@ module RubyNative
194
206
  data[:native_share_url] = url if url
195
207
  data[:native_icon] = resolved if resolved
196
208
  data[:native_selected] = "" if selected
197
- @items << @context.tag.div(data: data)
209
+ add(@context.tag.div(data: data))
198
210
  end
199
211
 
200
212
  def to_html
201
213
  @context.safe_join(@items)
202
214
  end
215
+
216
+ private
217
+
218
+ # See NavbarBuilder#add: collects the item and returns a blank, html-safe
219
+ # string so menu items read naturally with `<%= menu.item %>` in ERB.
220
+ def add(item)
221
+ @items << item
222
+ ActiveSupport::SafeBuffer.new
223
+ end
203
224
  end
204
225
  end
205
226
  end
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.10.12"
2
+ VERSION = "0.10.14"
3
3
  end
data/lib/ruby_native.rb CHANGED
@@ -22,6 +22,12 @@ module RubyNative
22
22
  mattr_accessor :screenshot_key
23
23
  mattr_accessor :screenshot_sign_in
24
24
 
25
+ # How the push endpoint finds the signed-in user to attach a device token to.
26
+ # Accepts a controller method name (Symbol) or a callable evaluated in the
27
+ # controller, e.g. `-> { Current.person }`. Defaults to `current_user`, so
28
+ # Devise apps need no configuration. Set via `RubyNative.configure`.
29
+ mattr_accessor :current_user_resolver, default: :current_user
30
+
25
31
  def self.configure
26
32
  yield self
27
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.12
4
+ version: 0.10.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti