Comments (2)
Hi @lister, I am planning the following behaviour:
directory.extend(DirectoryRepresenter).to_json(date: 10.days.ago)
The options passed to to_json
are now propagated to the reader method if it accepts arguments.
module DirectoryRepresenter
# ..
def files(options={})
super.modified_after(options[:date])
end
So, it is still up to you to write the filter logic, however, the representer simply passes all options to the accessors. What do you think?
from representable.
I need this functionality too, and the passing through of render local parameters to extended representers, consider something similar to the following (using HAL with roar-rails):
class Doctor
has_many :appointments
has_many :patients, :through => appointments
end
class Patient
has_many :appointments
has_many :doctors, :through => appointments
end
class Appointment
belongs_to :doctor
belongs_to :patient
end
Trying to retrieve a list of a doctors patients and appointments through: /doctors/1/patients.json
class PatientsController
represents :json, Patient
def index
patients = Doctor.find(params[:id]).patients
respond_with patients.to_a, :doctor_id => params[:id]
end
end
module PatientsRepresenter
collection :patients, :extend => PatientRepresenter
def patients
each
end
end
module PatientRepresenter
collection :appointments, :class => Appointment, :extend => AppointmentRepresenter, :embedded => true
link :self do |opts|
patient_url(self, opts[:doctor_id])
end
def appointments(options={})
Patient.find(self).appointments.where(doctor_id: options[:doctor_id])
end
end
Or is there another way I should be doing this?
from representable.
Related Issues (20)
- Using the :skip_parse option with JSON::Hash values produces Pipeline::Stop HOT 1
- XML Encoding? HOT 3
- Populator docs or examples? HOT 4
- XML namespaces
- Options hash passed to setter has incorrect value for collection properties
- Collection parsing raises an error if the value is nil HOT 4
- Document nested inherit: true
- Parsing null values results in property being set despite `reader` property present
- parsing array of arrays
- Bug in dependency package declarative-option update HOT 1
- Nested keys within hash are getting mutated HOT 5
- Custom writer: method is not invoked or not invoked correctly HOT 2
- Can't activate multi_json on (>= 1.14.1), already activated multi_json-1.11.3 HOT 3
- Representable doesn't work as expected on truffleruby-21.3.0 HOT 1
- Nokogiri deprecation warning
- `nested` tries to assign to non-existent property when parsing nil body HOT 7
- Combining nested include/exclude with regular include/exclude HOT 1
- Representing objects into objects using Representable::Object#to_object HOT 8
- Representable 4: problem when parsing looks at one field but wants to create two
- Representable 4: how to collect/write data when parsing?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from representable.