$ michaelis ruby
Michealis Dictionary
Translate: ruby (ingles-portugues)
ruby
ru.by
n 1 Min rubi, rubim. 2 cor do rubi. 3 algo semelhante ao rubi em cor como: vinho tinto, carbúnculo, sangue. 4 Typogr tipo de corpo 5 1/2. • vt ruborizar. • adj da cor do rubi, vermelho-vivo.
---
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
module ActsAsClassMethod | |
unless respond_to? :metaclass | |
define_method :metaclass do | |
class << self; self; end | |
end | |
end | |
def acts_as_class_method(*methods) | |
methods.each do |method| |
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
module HasStatuses | |
def has_statuses(*statuses) | |
self.const_set "Statuses", Module.new | |
statuses.each { |status| self::Statuses.const_set status.to_s.upcase, status } | |
self.const_set "ALL_STATUSES", self::Statuses.constants.collect { |constant| self::Statuses.const_get(constant) } | |
end | |
Object.send :extend, 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
module WhereOr | |
def where_or(*scopes) | |
conditions = scopes.inject(self) { |scoped, scope| scoped.send(scope) } | |
conditions = conditions.where_values.map { |where_value| where_value.respond_to?(:to_sql) ? where_value.to_sql : where_value } | |
conditions = conditions.join(" OR ") | |
where(conditions) | |
end | |
ActiveRecord::Base.send :extend, 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
require "active_support/inflector" | |
module Modularizable | |
def modularize(target, params={}) | |
ancestors = params[:in] || [] | |
ancestors << target | |
ancestors.collect { |item| item.to_s.camelize }.join("::").constantize | |
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
class Paginator | |
DEFAULT_PAGE = 1 | |
DEFAULT_PER_PAGE = 5 | |
attr_reader :page | |
attr_reader :per_page | |
def paginate(collection, options={}) | |
setup(options) |
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
Article.all( | |
:select => "articles.id, articles.title, slugs.name", | |
:joins => "INNER JOIN slugs | |
ON slugs.sluggable_type = 'Article' AND | |
slugs.sluggable_id = articles.id AND | |
slugs.id = (SELECT id | |
FROM slugs | |
WHERE slugs.sluggable_type = 'Article' AND | |
slugs.sluggable_id = articles.id | |
ORDER BY slugs.created_at DESC |
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
By default, Rails 3.2 loads everything in app/javascripts and everything in app/stylesheets on | |
every page, despite controller-specific file naming. If you want to load controller-specific | |
files only on views from their respective controllers, you need to change the manifests and the | |
layout. The basic idea is to NOT require the entire trees, but only specific subfolders, in the | |
manifests, and then load the controller-specific files separately in the layout. | |
Any file you DO want loaded on every page should be placed in app/assets/javascripts/general or | |
app/assets/stylesheets/general. | |
For this to work in production, you also need to ensure that the individual files are precompiled by modifying your production.rb file, listing all of the controller-specific files. |
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 Credential | |
include ActiveModel::Validations | |
attr_accessor :screen_name, :oauth_token, :oauth_secret, :token, :description | |
validates_presence_of :screen_name, :oauth_token, :oauth_secret, :message => 'required' | |
validate :user_exists, :unless => :errors? | |
def initialize(attributes = {}) | |
attributes.each { |k, v| set_recognized_attribute(k, v) } |
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
# This is part of my .pryrc. | |
# I put this at the section where I load Rails stuff, so I can use Pry instead of IRB | |
# for my Rails Console sessions | |
# Once this is loaded, just run the display_routes method from the console to see the same output that rake routes displays. | |
# I think it's better because I always leave a Rails console session running :) | |
require 'rails/application/route_inspector' |