Skip to content

Instantly share code, notes, and snippets.

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
# 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
##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"
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
(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'",
# 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
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)}