Skip to content

Instantly share code, notes, and snippets.

@dyoder
Created December 2, 2010 01:24
Show Gist options
  • Select an option

  • Save dyoder/724574 to your computer and use it in GitHub Desktop.

Select an option

Save dyoder/724574 to your computer and use it in GitHub Desktop.
Current Example - Listing 1
class Acme::Web::Adapters::Article < Acme::Web::Adapter
resource Acme::Resources::Article
Comments = Acme::Web::Adapters::Comments
version "1.0" do
path "article", :name
get [ json, xml, html ]
authorized do
put json => json, xml => xml
delete
end
representation html do |resource|
Acme::Web::Views::Article.render(resource)
end
schema :title, :content, :published,
{ :comments_url => :url }
end
version "1.1" do
inherit "1.0"
path "articles", :name
schema :title, :subtitle, :content, :published,
{ :comments_url => :url }
end
end
class Acme::Resources::Article
include Current::Resources::Mixin
end
Acme::Resources::Article["introduction"] = {
:title => "Introducing Current", :published => Time.now,
:content => "This is the introduction" }
article = Acme::Resources::Article["introduction"]
article.content # => "This is the introduction"
article.content = "We need a better introduction!"
Acme::Resources::Articles["introduction"] = {
:title => "Introduction To Current", :published => Time.now,
:content => "This is the introduction" }
Acme::Resources::Articles["introduction"].title
# => "Introduction To Current"
Acme::Resources::Articles.to_h
# => { :title => "Introduction To Current", ...
Acme::Resources::Articles["introduction"].delete
Acme::Resources::Articles["introduction"] # => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment