Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit e2e433fda095a8721bf525a8258b2cc2910ab907 @mikelaurence mikelaurence committed Nov 8, 2011
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in bootstripe-rails.gemspec
+gemspec
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "bootstripe-rails/version"
+
+Gem::Specification.new do |s|
+ s.name = "bootstripe-rails"
+ s.version = Bootstripe::Rails::VERSION
+ s.authors = ["Mike Laurence"]
+ s.email = ["mike@bytebin.com"]
+ s.homepage = "http://bytebin.com"
+ s.summary = %q{A handful of useful additions for Rails}
+ s.description = %q{A handful of useful additions for Rails}
+
+ s.rubyforge_project = "bootstripe-rails"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ s.add_runtime_dependency "rails"
+end
@@ -0,0 +1,7 @@
+require 'bootstripe-rails/version'
+
+# Additions
+require 'boostripe-rails/model_additions'
+
+# Validation
+require 'boostripe-rails/validators'
@@ -0,0 +1,22 @@
+module ActiveRecord
+ class Base
+ def self.loaded_models
+ ActiveRecord::Base.send(:descendants)
+ end
+
+ def self.randomize
+ order 'RANDOM()'
+ end
+
+ def self.ordered
+ order 'created_at ASC'
+ end
+
+ def clone!(params = {})
+ cl = self.class.new
+ time = Time.current
+ cl.send :attributes=, HashWithIndifferentAccess.new(self.attributes).except(:id).merge(:created_at => time, :updated_at => time).merge(params), false
+ cl
+ end
+ end
+end
@@ -0,0 +1,21 @@
+module ActiveModel
+ module Validations
+ class ZipcodeValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ record.errors[attribute] << 'is not properly formatted' unless /^[0-9]{5}([- ]?[0-9]{4})?$/.match(value)
+ end
+ end
+
+ class EmailValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ record.errors[attribute] << 'is not properly formatted' unless /^[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i.match(value)
+ end
+ end
+
+ class PhoneValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ record.errors[attribute] << 'is not properly formatted' unless /1?\W*([2-9][0-8][0-9])\W*([2-9][0-9]{2})\W*([0-9]{4})(\se?x?t?(\d*))?/.match(value)
+ end
+ end
+ end
+end
@@ -0,0 +1,5 @@
+module Bootstripe
+ module Rails
+ VERSION = "0.2.0"
+ end
+end

0 comments on commit e2e433f

Please sign in to comment.