Skip to content

Instantly share code, notes, and snippets.

@marcosinger
marcosinger / config.ru
Created February 29, 2012 23:49
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
require "rails"
# Let's load only action controller. If you want
# to use active record, just require it as well.
require "action_controller/railtie"
class MyApp < Rails::Application
def give_specific_permissions_to_user(user, permission)
profile = if user.profiles.empty?
user_profile = Iceleres::UserProfile.create :user_id => user.id, :profile => Factory(:profile)
user_profile.profile
else
user.profiles.first
end
profile.permissions << Factory(permission)
end
# encoding: utf-8
module Iceleres
module HasPhoneNumber
def has_phone_number(name, options={})
options.assert_valid_keys [:validate]
define_method "#{name}_phone_number=" do |phone_number|
self.send("#{name}_phone=", phone_number.number)
self.send("#{name}_phone_areacode=", phone_number.area_code)
end
# encoding: utf-8
module Iceleres
class PhoneNumber
include EnumerateIt
include ActiveModel::Validations
ATTRIBUTES = [:area_code, :number, :type, :validation]
PHONE_FORMAT = /^[1-9]\d{3}[-\s]?\d{4}/
attr_accessor *ATTRIBUTES