module Picatrix::Mason
Public Instance Methods
filter(collection)
click to toggle source
# File lib/picatrix/templates/mason.rb, line 86 def filter(collection) proc do |path, params| if params[:newest] { "<%= @prefix %>filter": Mason::Filter.new( { href: "http://localhost:9292/#{path}?filter=newest", isHrefTemplate: true, method: Mason::HTTPVerb::GET, title: "Show the newest additions to #{collection}" } ).to_hash } else { "<%= @prefix %>filter": Mason::Filter.new( { href: "http://localhost:9292/#{path}?$select&{field1}={value1}&{field2}={value2}", isHrefTemplate: true, method: Mason::HTTPVerb::GET, title: "Filter using $select on schema fields" } ).to_hash } end end end
mason_up(type)
click to toggle source
# File lib/picatrix/templates/mason.rb, line 3 def mason_up(type) if type.to_s.pluralize == type proc do |path, params| { up: Mason::Up.new( { href: "http://localhost:9292/#{<%= @root_path %>}" } ).to_hash } end else proc do |path, params| { up: Mason::Up.new( { href: "http://localhost:9292/#{path.pluralize}" } ).to_hash } end end end def mason_self(item) proc do |path, params| if params[:item_id] { self: Mason::Self.new( { href: "http://localhost:9292/#{path}/#{params[:item_id]}" } ).to_hash } else { self: Mason::Self.new( { href: "http://localhost:9292/#{path}" } ).to_hash } end end end def edit(item) proc do |path, params| { "<%= @prefix %>edit": Mason::Edit.new( { href: "http://localhost:9292/#{path}/#{params[:item_id]}", method: Mason::HTTPVerb::PATCH } ).to_hash } end end def remove(item) proc do |path, params| { "<%= @prefix %>remove": Mason::Remove.new( { href: "http://localhost:9292/#{path}/#{params[:item_id]}", method: Mason::HTTPVerb::DELETE } ).to_hash } end end def create(collection) proc do |path, params| collection_name = collection.to_s.camelize { "<%= @prefix %>create": Mason::Create.new( { href: "http://localhost:9292/#{path}", method: Mason::HTTPVerb::POST, title: "Create a new #{collection_name}", create_template: "#{collection_name}CreateTemplate".constantize.new({}) } ) } end end def filter(collection) proc do |path, params| if params[:newest] { "<%= @prefix %>filter": Mason::Filter.new( { href: "http://localhost:9292/#{path}?filter=newest", isHrefTemplate: true, method: Mason::HTTPVerb::GET, title: "Show the newest additions to #{collection}" } ).to_hash } else { "<%= @prefix %>filter": Mason::Filter.new( { href: "http://localhost:9292/#{path}?$select&{field1}={value1}&{field2}={value2}", isHrefTemplate: true, method: Mason::HTTPVerb::GET, title: "Filter using $select on schema fields" } ).to_hash } end end end end