Skip to content

Instantly share code, notes, and snippets.

@ehlyzov
Created August 21, 2009 08:45
Show Gist options
  • Save ehlyzov/171732 to your computer and use it in GitHub Desktop.
Save ehlyzov/171732 to your computer and use it in GitHub Desktop.
module ProteinPresenter
custom_presenter = lambda { |att| att.to_s }
# тут делаются презентеры, хотя лучше из выносить вообще в
# отдельные файлы. Существующих возможностей для этого куча.
presenter :title, lambda {|att| attr.capitalize }
presenter :num, custom_presenter
presenter :m2, lambda {|m| m.to_s.capitalize }
end
output :json
alias :protein_hits, :proteins
context :root, :storage => :hash # {}
context :proteins, :storage => :array, :anchor => :data # { :data => [] }
context.each do |protein|
protein.extend(ProteinPresenter)
context :protein, :storage => :hash # { :data => [{}]
attributes :all, :except => [:created_at, :updated_at]
methods :m1, :m2, [:m3, param1, param2]
context :taggings, :storage => :array # {:data => [{..., :taggings => []}]
context.each do |tag|
context :tag, :storage => :hash
attributes :only => [:title, :creator_id]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment