Skip to content
This repository

Sketch of parameter filtering (nunu) #39

Merged
merged 1 commit into from about 2 years ago

3 participants

Matt Burke Joshua Davey Stephen Caudill
Matt Burke

It looks like nunu is a sketch and a refactoring of the existing API, moving towards the sketch/README. So I've updated the sketch & readme with the idea from #38. In that issue, @voxdolo suggested configuring a default in an exposure block, but it seems like it's simpler to configure per-expose, so that's what I've sketched.

(a) Does this look good?

(b) What's the next step I can take to help make a configurable params (or nunu) a reality?

Joshua Davey
Collaborator

I like this, and it seems reasonable to pull this in.

Stephen Caudill
Owner

@spraints thanks! looks good! consider it merged.

Stephen Caudill voxdolo closed this March 30, 2012
Stephen Caudill voxdolo merged commit a4e500e into from March 30, 2012
Stephen Caudill
Owner

@spraints as to (b), it's a bit wild-wild west right now. the README and sketch roughly outline what we want to happen, so if anything in there tickles your fancy, please dive in and work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 15, 2012
Matt Burke Add custom parameter handling to the readme/sketch. 5cc4bd9
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 18 additions and 0 deletions. Show diff stats Hide diff stats

  1. 4  README.md
  2. 14  sketch.rb
4  README.md
Source Rendered
@@ -97,6 +97,10 @@ Specify the finder method:
97 97
 
98 98
     expose(:company, finder: :find_by_slug)
99 99
 
  100
+Specify the parameter accessor:
  101
+
  102
+    expose(:company, params: :company_params)
  103
+
100 104
 ### Getting your hands dirty
101 105
 
102 106
 While we try to make things as easy for you as possible, sometimes you just
14  sketch.rb
@@ -232,6 +232,20 @@ class Controller
232 232
   expose(:whatever, model: :thing)
233 233
   expose(:whatever, model: :thing, :finder: :find_by_thing, scope: :things)
234 234
 
  235
+  # filtering parameters
  236
+  expose(:whatever, attributes: [:ok, :also_ok])
  237
+
  238
+  # using a custom / filtered set of parameters
  239
+  expose(:whatever, params: :whatever_params)
  240
+  def whatever_params
  241
+    attrs = params[:whatever] || {}
  242
+    if current_user.admin?
  243
+      attrs.slice(:ok, :also_ok, :ok_for_admin)
  244
+    else
  245
+      attrs.slice(:ok, :also_ok)
  246
+    end
  247
+  end
  248
+
235 249
   # using the default behavior of decent_exposure with an app specific twist
236 250
   expose(:whatever, orm: :data_mapper) { app_specific(framework.execute_default) }
237 251
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.