This file contains hidden or 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
module Merb::Cache | |
class MutexFetchStore < StrategyStore | |
def initialize(config = {}) | |
super(config) | |
@interval = config[:sleep_interval] || 0.1 | |
@timeout = config[:timeout] || 0.5 | |
end | |
def writable?(key, parameters = {}, conditions = {}) | |
contexts.any? {|c| c.writable?(key, parameters, conditions)} |
This file contains hidden or 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
# current code: | |
unless @users = cache_get("active_users") | |
@users = User.all(:active => true) | |
cache_set("active_users", @users) | |
# object caching can be used to avoid pulling huge amounts of data | |
# from the database. | |
# you could have calle cache_set with an expiration time as well: | |
# cache_set("active_users", @users, 10) | |
end |
This file contains hidden or 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
(rdb:1) e | |
#<NoMethodError: undefined method `product_id' for #<Shirt:0x3eafc60>> | |
(rdb:1) Shirt.properties | |
#<PropertySet:{#<Property:Shirt:id>,#<Property:Shirt:type>,#<Property:Shirt:code>,#<Property:Shirt:name>,#<Property:Shirt:description>,#<Property:Shirt:unit_price>,#<Property:Shirt:available_on>,#<Property:Shirt:is_discontinued>,#<Property:Shirt:slug>,#<Property:Shirt:vote_mean>,#<Property:Shirt:available>,#<Property:Shirt:designer_id>,#<Property:Shirt:created_by>,#<Property:Shirt:user_id>}> | |
(rdb:1) pp e.backtrace | |
["/opt/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.3/lib/dm-validations/numeric_validator.rb:17:in `send'", | |
"/opt/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.3/lib/dm-validations/numeric_validator.rb:17:in `call'", | |
"/opt/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.3/lib/dm-validations/contextual_validators.rb:48:in `execute'", |
This file contains hidden or 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
require 'pathname' | |
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper' | |
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES | |
describe "STI Resources" do | |
before do | |
class Product | |
include DataMapper::Resource | |
property :id, Integer, :serial => true |
This file contains hidden or 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
##haml | |
-form_for @order, :action => url(:shipping) do | |
.checkoutWrapper | |
-fields_for @order.shipping_info do | |
.shippingAddress | |
%h4 | |
Shipping Address | |
%fieldset#shippingAddress | |
%div | |
%span=text_control :name, :label => "Name" |
This file contains hidden or 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
# implementation | |
module Merb::Cache::CacheMixin | |
def fetch_partial(template, opts={}, conditions = {}) | |
template_id = template.to_s | |
if template_id =~ %r{^/} | |
template_path = File.dirname(template_id) / "_#{File.basename(template_id)}" | |
else | |
kontroller = (m = template_id.match(/.*(?=\/)/)) ? m[0] : controller_name | |
template_id = "_#{File.basename(template_id)}" | |
end |
This file contains hidden or 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
def eager_cache(trigger_action, target_action, conditions = {}) | |
if target_action.is_a? Array | |
target_controller, target_action = *target_action | |
conditions[:controller] = target_controller | |
end | |
after("_eager_cache_#{trigger_action}_after", conditions.only(:if, :unless).merge(:with => [conditions.except(:if, :unless)], :only => trigger_action)) | |
alias_method "_eager_cache_#{trigger_action}_after", :_eager_cache_after | |
end |
This file contains hidden or 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 Application < Merb::Controller | |
def _call_action(action) | |
repository(:default) { catch(:halt) { super(action) }} | |
end | |
end |
This file contains hidden or 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 Sessions < Application | |
def create | |
session.authenticate! #authenticates the user by username/password OR openid, raises an Unauthenticated if the user cannot be authenticated | |
redirect(url(:home)) | |
end | |
end | |
class Session | |
def authenticate! |
This file contains hidden or 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
#models | |
class Cat < Mamal; end # loads the 'mamal.rb' if Mamal is undefined | |
#controller | |
Cats < Mamals; end # if mamals is a controller, is this kosher? |
OlderNewer