Skip to content

Instantly share code, notes, and snippets.

View rlburkes's full-sized avatar

Randy Burkes rlburkes

View GitHub Profile
class BuildPropertyAssociationsOnExports < ActiveRecord::Migration
...
class Property < ActiveRecord::Base
attr_accessible :hierarchical
end
...
def up
class RenameHierarchicalToEnumeratedInProperties < ActiveRecord::Migration
def change
rename_column(:properties, :hierarchical, :enumerated)
end
end
class BuildPropertyAssociationsOnExports < ActiveRecord::Migration
...
class Property < ActiveRecord::Base
attr_accessible :hierarchical
def enumerated?
if defined?(super)
super
else
@rlburkes
rlburkes / 1.rb
Last active August 29, 2015 13:56
class MarkProductExportsWhichMeetAllRequirements < ActiveRecord::Migration
Export = Class.new(ActiveRecord::Base)
class ProductExport < Export
attr_accessible :meets_requirements
def meets_all_requirements?
# Do some complex business logic which cannot be expressed via sql query
end
@rlburkes
rlburkes / 2.rb
Last active August 29, 2015 13:56
class MarkProductExportsWhichMeetAllRequirements < ActiveRecord::Migration
class Export < ActiveRecord::Base
attr_accessible :meets_requirements
def meets_all_requirements?
# Do some complex business logic which cannot be expressed via sql query
end
end
@rlburkes
rlburkes / 3.rb
Last active August 29, 2015 13:56
class MarkProductExportsWhichMeetAllRequirements < ActiveRecord::Migration
class Export < ActiveRecord::Base
attr_accessible :meets_requirements
self.inheritance_column = nil
def meets_all_requirements?
# Do some complex business logic which cannot be expressed via sql query
end
NoMethodError: undefined method `meets_all_requirements?' for #<ProductExport:0x007fae799b32a8>
@rlburkes
rlburkes / djyiap.rb
Last active August 29, 2015 14:08
Example of what Delayed::Plugins::YouthInAsiaPlugin might look like
# Automatically kill jobs' worker when it finishes
# if it used more memory than allotted.
# Ali-G: Lets talk about doctors who is ending the life of people who is suffering.
# Ali-G What’s it got to do with the youth in Asia I mean it aiint their fault these peoples is dying, they’s thousands of miles away.
# Doctor: Euthanasia means mercy killing, it literally means dying well. We're not talking about the youth in Asia, (or) the youth in Africa.
# Ali-G: But why is you blaming that on the asian kids or whatever?
module Delayed
module Plugins
class YouthInAsiaPlugin < Delayed::Plugin
module WorkerExtensions
WorkerProcess = Struct.new(:id, :name, :app_name, :size) do
ONE_X_WORKER_SIZE = 512.0
TWO_X_WORKER_SIZE = 1024.0
def memory_ceiling
size == 1 ? ONE_X_WORKER_SIZE : TWO_X_WORKER_SIZE
end
end
# Wouldn't it be great if you could have STI like functionality
# without needing to encode strings of class names in the database?
# Well today is your lucky day! Discriminable Model is here to help.
#
# Simply specify your models desired type column, and provide a block to
# do the discrimination. If you want the whole STI-esque shebang of properly
# typed finder methods you can supply an array of 'discriminate_types' that will
# be used to apply an appropriate type.
#
# class MyModel < ActiveRecord::Base