Run this on ruby 1.9
require 'delegate'
class Bam < SimpleDelegator
def bam
defined? Bam
end
$ cat ~/Library/LaunchAgents/org.memcached.plist | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>org.memcached</string> | |
<key>KeepAlive</key> | |
<true/> | |
<key>ProgramArguments</key> |
class SimulateTraffic | |
def initialize | |
@dates = (first_date_of_last_month..Date.today).to_a | |
@types = [:pageviews, :subscriptions, :shares, :clicks] | |
end | |
def first_date_of_last_month | |
prev_month = Date.today.prev_month | |
Date.new(prev_month.year, prev_month.month, 1) |
# ruby 1.9.3-p125-perf | |
# Rails 3.2.0 | |
# app/bam/ham.rb | |
module Bam | |
class Ham | |
end | |
end | |
# on rails console |
Run this on ruby 1.9
require 'delegate'
class Bam < SimpleDelegator
def bam
defined? Bam
end
Caveat: I have not read James Coplien book about DCI. | |
But to put simply: Data Context Interaction (Roles) is a technique to capture the run-time behavior of your system. I'll leave the benefits to your imagination, and gleaning from further reading of numerous sources about the subject. | |
How do we apply DCI to Rails? Here's one proposed folder structure: | |
app/contexts/ | |
app/roles/ | |
app/models/ |
# config/initializers/devise.rb | |
# | |
# We now ask Warden to use :vip_authenticatable when authenticating. | |
# | |
# Also, we instruct Warden to load User from session without any default scoping. | |
# | |
Devise.setup do |config| | |
config.warden do |manager| | |
require Rails.root+'lib/vip_authenticable' | |
manager.default_strategies(scope: :user).unshift :vip_authenticatable |
# lib/vip_authenticatable.rb | |
# | |
# We introduce :vip_authenticatable strategy to Warden. | |
# With this strategy your login form might look something like | |
# | |
# <form action="/path/to/create/session"> | |
# <input name="vip[:id]" placeholder="Enter your VIP No."> | |
# <input type="submit"> | |
# </form> | |
# |
# Our User model with default_scope of active users, | |
# and a :vip scope | |
# | |
class User | |
include Mongoid::Document | |
field :status | |
# now only active users can be authenticated | |
default_scope where(status: 'active') |
# So I was trying to use named route helpers in sprockets, and the app was hosted in a subdirectory. | |
# This is what I came up with. Please share your hackeries. | |
# | |
# using named routes in sprocket Rails 3.1 | |
# you can use this in app/assets/javascripts/bam.js.erb | |
# or any other erb sprocket asset | |
Rails.application.routes.url_helpers.bam_path( | |
:script_name => ApplicationController.config.relative_url_root | |
) |