This file contains hidden or 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 Product < ActiveRecord::Base | |
has_many :fields, :as => :attributable, :dependent => :destroy | |
accepts_nested_attributes_for :fields | |
end | |
class Field < ActiveRecord::Base | |
belongs_to :attributable, :polymorphic => true | |
belongs_to :column | |
scope :with_column, select("fields.*, columns.column_name AS 'name'").joins(:column) |
This file contains hidden or 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
def file_copy(src, dest) | |
File.open(dest, 'wb') { |f| f.puts(File.read(src)) } | |
end |
This file contains hidden or 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
def word_wrap(word, len = 22) | |
if word.size < len | |
word | |
else | |
new_word = [] | |
parts = word.split(/\s/).map { |p| p.strip } | |
while part = parts.shift and (new_word.join(" ").size + part.size) < len | |
new_word << part | |
end |
This file contains hidden or 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
function Car () { | |
} | |
Car.prototype.extDirectOptions = function(options) { | |
this.extDirectOptions = options; | |
} | |
Generator.prototype.controllerMetadata = function() { | |
// find controller in config.controllersDir |
This file contains hidden or 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 Product | |
include Mongoid::Document | |
referenced_in :group | |
end | |
class Group | |
include Mongoid::Document | |
references_many :products, :stored_as => :array, :inverse_of => :group | |
end |
This file contains hidden or 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 Frequency | |
# A small dsl written in ruby to work with frequency events (never, sometimes, always..) | |
# | |
# | |
# Alteracoes: | |
# * removi "if block_given?" e passei &block como parametro para #execute_with_probability | |
# para remover duplicacao | |
# * mudei #correct_if_string | |
module Frequency | |
NORMALLY = 0.75 |
NewerOlder