- decreases startup time by not loading all your models
- makes it possible to preload config/environment.rb and still test models -> spin/zeus
- makes dependencies obvious
- replaces ActiveRecord magic with ruby
- makes your app Rails 4 ready
This file contains 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
<?php | |
/** | |
* The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without, and class names to foreign keys. | |
* This solution is partitionaly based on Ruby on Rails ActiveSupport::Inflector (c) David Heinemeier Hansson. (http://rubyonrails.org), MIT license | |
* @see http://api.rubyonrails.org/classes/Inflector.html | |
* | |
* @author Roman Sklenář | |
* @copyright Copyright (c) 2009 Roman Sklenář (http://romansklenar.cz) |
This file contains 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
<?php | |
/** | |
* Provide very simple abstraction above database row (DibiRow replacement) | |
* | |
* @author Roman Sklenář | |
* @copyright Copyright (c) 2009 Roman Sklenář (http://romansklenar.cz) | |
* @license New BSD License | |
* @version 0.1 |
This file contains 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
<?php | |
/* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 String | |
def to_bool | |
case | |
when self == true || self =~ /^(true|t|yes|y|1)$/i | |
true | |
when self == false || self.blank? || self =~ /^(false|f|no|n|0)$/i | |
false | |
else | |
raise ArgumentError.new "invalid value for Boolean: '#{self}'" |
This file contains 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
# Unobtrusive RESTful dynamic/dependent select menus for Ruby on Rails 3 and jQuery | |
# | |
# USAGE (with Formtastic): | |
# | |
# match = form.object | |
# seasons = Season.all | |
# rounds = match.season.nil? ? Array.new : match.season.rounds | |
# | |
# form.input :season, :as => :select, :collection => seasons, :include_blank => false, :prompt => true, :input_html => { :id => :season_id } | |
# form.input :round, :as => :select, :collection => rounds, :include_blank => false, :prompt => true, :input_html => { :id => :round_id, |
This file contains 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 Foo < ActiveRecord::Base | |
attr_accessor :timestamp_control | |
after_initialize { self.timestamp_control ||= Time.zone.now } | |
before_validation :overwrite_check | |
def overwrite_check | |
errors[:base] << I18n.t('errors.messages.overwritten') if updated_at > timestamp_control | |
end |
This file contains 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 'open-uri' | |
require 'roo' | |
apple = Company.create! do |company| | |
company.name = "Apple Inc." | |
company.code = "AAPL" | |
company.messages_url = "http://finance.yahoo.com/rss/headline?s=#{company.code}" | |
company.stocks_url = "http://ichart.finance.yahoo.com/table.csv?s=#{company.code}" | |
end |
This file contains 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
# company_names = (1..15).map { Faker::Company.name } | |
company_names = %w[Design Marketing Branding Stores Mobile Desktop Software Hardware] # departments | |
data = (1..500).map do | |
[ company_names.sample, | |
name = Faker::Name.name, | |
Faker::Internet.free_email(name.parameterize), | |
Faker::Internet.user_name(name.parameterize), | |
SecureRandom.urlsafe_base64(10).gsub('-', '') ] | |
end |
OlderNewer