Revision 10ef282cff47 () - Diff

Link to this snippet: https://friendpaste.com/4VknN8S8AqXn2oZNgZAayj
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Dynamically defining properties
>> class Mocha < RelaxDB::Document; end
>> Mocha.new.save
>> m = Mocha.new
>> m.class.instance_eval { property :shot }
>> m.shot = "strong"
>> m.save
>> Mocha.all
=> [#<Mocha:9738370, _id: "779", _rev: "3750419526", shot: "strong">, #<Mocha:9729290, _id: "883", _rev: "2014351092">]

# Dynamically defining properties - another approach
Mocha.module_eval { property :chilled }

# Parameterizing a view request
@cds = Cd.all.sorted_by(:year_of_release) { |q| q.startkey(2005).descending(true) }

# Updating and saving
@cd.set_attributes(params[:cd])
# The following might be a little more succinct, but
# you'd need to pass the document revision to the web client
Cd.new(params[:cd]).save