This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
synchronize: (block) -> | |
context = new Joosy.SynchronizationContext(this) | |
block.call(this, context) | |
@wait context.expectations, => context.after.call(this) | |
context.actions.each (data) => | |
data[0].call this, => | |
@trigger data[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream hashbang-localhost { | |
server localhost:22333; | |
} | |
server { | |
listen 80; | |
server_name ...; | |
location / { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example taken from http://quickleft.com/blog/presenters-as-a-solution-to-asjson-woes-in-rails-apis | |
class Api::V1::ResourcePresenter | |
attr_reader :resource | |
def initialize( resource ) | |
@resource = resource | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/decorators/article_decorator.rb | |
class ArticleDecorator < ApplicationDecorator | |
decorates :article | |
def the_very_important_fields_set( include_root = false ) | |
data_hash = { | |
:attr1 => att1, | |
:attr2 => attr2 | |
} | |
data_hash = { :resource => data_hash } if include_root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/decorators/article_decorator.rb | |
class ArticleDecorator < ApplicationDecorator | |
decorates :article | |
def the_very_important_fields_set( include_root = false ) | |
data = Jbuilder.encode do |j| | |
j.(self, :attr1, :attr2) | |
end | |
data = { :resource => data } if include_root | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Article < ActiveRecord::Base | |
include Heimdallr::Model | |
belongs_to :owner, :class_name => 'User' | |
restrict do |user, record| | |
if user.admin? | |
# Administrator or owner can do everything | |
scope :fetch | |
scope :delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Article.restrict(current_user).where(:typical => true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlesController < ApplicationController | |
include Heimdallr::Resource | |
load_and_authorize_resource | |
# or set the name explicitly: | |
# | |
# load_and_authorize_resource :resource => :article | |
# if nested: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Article.restrictions(current_user).allowed_fields[:create] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
article = Article.restrict(current_user).first | |
@article = article.implicit | |
@article.protected_thing # => nil |