News: Sensation!!! Hydrochlorothiazide Nylidrin Cortisol Dont buy on black market get viagra legally Hydroxyzine Prescriptions on line phentermine Snorting xanax Methamphetamine Between difference levivia viagra Fastin Dimethothiazine Weight loss phentermine Congress viagra Lowest prices on phentermine Urine drug testing of tramadol Klonopin Clomid Hydrocodone prescription online Thiotepa Generic price viagra Fexofenadine Diet pill phentermine Ceclor Generic uk viagra Monopril Phentermine lortab online Vicodin prescription Minocin Phentermine cheapest Phentermine and methamphetamine Online viagra sale Free sample viagra Buy viagra now Glycopyrrolate Long term phentermine use Ambien prescription Buy phentermine online cod How to inject xanax pills Maxzide Clarinex Xanax high Daunorubicin Cefaclor Atropine Uk online pharmacy phentermine Generic xanax xr Xanax online overnight Probucol Foradil Information about viagra Online pharmacy phentermine Side effects of the drug tramadol Propylthiouracil Adipex meridia phentermine xenical Xanax ambien Buy phentermine online cheap Macular degeneration caused by viagra Xanax liver damage Paromomycin Xanax grapefruit juice Veterinary use of tramadol Lescol Viagrafix corporation Add a link viagra Hydroxyurea Buy xanax no perscription needed amex accepted Phentermine 37.5 diet pills Free xanax Nasacort aciphex phentermine actos imitrex Xanax overnight Etanercept Amoxicillin Colestipol Buy generic xanax Does phentermine interact with hydrocodone Hytrin Quinidine Viagra lawsuits Dangers of phentermine heart Meridia side effects Prozac Phentermine cheap no prescription Diphenhydramine Cheapest fioricet Pravastatin Phentermine side effects dangers Phentermine medication Tramadol withdrawal Tramadol side effects Ambien online Luxury hotel rome xanax description Buy generic viagra Atropine Vicodin effects Norvasc Drug testing xanax Penicillin Phentermine sameday overnight saturday delivery Molindone Hydrocodone drug Imuran Diphenoxylate Hydrocodone medication Cialis immunity Discount viagra perscription drug Diet no phentermine pill prescription Mebendazole Viagra price compare Bretylium Colace Uk viagra body building from sports supplement Herbal viagra alternatives Clarithromycin Diazepam Pantoprazole Phentermine lose weight loss diet pills Cheapest phentermine Viagra generic brand Hydrocodone info Cialis side effects Cialis levitra vs Gemfibrozil Xanax shipped cod Phentermine buy Viagra online ordering Flexeril Generic name online qoclick tramadol Phentermine eprescriptions Order phentermine diet pill Nafcillin Buy cheap no phentermine prescription Xanax cod Elidel Phentermine ship to ky Viagra 100 mg Buy cheap viagra Levivia vs viagra Xanax online no prescription Cheap online order viagra Order ambien online Levitra cialis info Add link phentermine purchase Ampicillin Line prescription viagra Cheapest viagra uk Haloperidol Bricanyl Dexfenfluramine Different types of phentermine Vincristine Prazosin Comparison viagra cialis levitra Phentermine shipped to tn Buy Zyban Viagra suppliers Phentermine referring report urls Best price for viagra in the uk Hydrocodone cough syrup Viagra and ischemic optic neuropathy Free ambien Cefonicid Methylphenidate Buying xanax online Lincomycin Adapalene Pioglitazone Cod overnight tramadol Cyclothiazide 180 tramadol 92 accepted cod phentermine Norfloxacin How does xanax work Viagra xenical Alternative new viagra Cheap phentermine 37.5 mg Dicyclomine Hydrocodone withdrawal Hydrocodone description Phentermine message boards Erection viagra Phentermine 90 day Phentermine with free shipping Symptom of vicodin addiction Phentermine diet medication Phentermine prescriptions online physiphen online Non prescription phentermine Codeine Phentermine yellow Chep phentermine Prometrium Azathioprine Viagra dosage Cyclobenzaprine Effexor Prempro Female use viagra Phentermine ky Ssri phentermine heart Natural viagra alternatives Phentermine np with hoodia Online pharmacy duromine viagra international Amiloride Phentermine pillstore Lamivudine Pictures of xanax Amaryl Viagra dangers Zantac Acetaminophen e hydrocodone 2mg xanax Tramadol drug interaction Cheap viagra Accutane Phentermine cod overnight Xanax without prescription Viagra for woman information Mexican pharmacies online+xanax Loracarbef Black market viagra Oxycontin xanax bars perclesept and lortab wha Acetazolamide Shipping phentermine to florida Cheap hydrocodone Symptom tramadol withdrawal Phentermine diet pill Climara Aminophylline Casanthranol Buy ambien online Nalorphine Buy no phentermine prescription Cyber pharmacy viagra Phentermine $70 no prescription Real phentermine Cialis tablet Phentermine ups shipped Ionamin phentermine Killer pain tramadol Dothiepin Aspirin Adipex p phentermine Colon cleanse ambien Viagra in woman Cialis tadalafil How long does phentermine stay in your body Piroxicam Biaxin Insulin Xanax withdrawal effects Fenoterol Mepenzolate Ceftin Methsuximide Meridia order Viagra pill Chlorprothixene Buy generic hydrocodone Online doctors perscriptions xanax steroids Injecting phentermine Hydralazine Buy phentermine cheap Buy phentermine online without a prescription Mirena Does phentermine really work Nutmeg Hydroxyzine Buy Wellbutrin Cholecalciferol Adipex cheap phentermine Counterfeit viagra Bromocriptine Phentermine resident sale virginia Herbal viagra for woman Tramadol pharmacy Milrinone Phentermine 37.5 adipex 37.5 mg Buy prescription tramadol without 100 mg viagra Does it viagra work Cialis versus viagra Trimethaphan Levoxyl Mechlorethamine Suicide xanax Xanax medication Online phentermine pharmacy best cheapest Phentermine a159 Herbal viagra for women Furosemide Niaspan Ethoheptazine Cyclobenzaprine Mail order viagra Bricanyl Oxycontin xanax bars percasettes and lor tabs Lisinopril with viagra Phentermine vs adipex p What does xanax look like Plicamycin Buy cheap fioricet Gatifloxacin Sell viagra online Valium vicodin Buy xanax cod Nicardipine Atenolol viagra Lovastatin Phentermine hcl side effects Buy phentermine online with paypal Where can i buy viagra Spectinomycin Cheap perscription phentermine Zoloft Alternative herbal viagra Soma gallery Isosorbide Viagra cialis levitra dose comparison Extra cheap phentermine Compare generic viagra prices Permethrin Nicoumalone Bupropion Side effects from viagra Methadone and xanax Is there a phentermine shortage Pepcid Drug viagra Dextrothyroxine Valtrex Paris france cheep viagra Mitoxantrone Cheapest phentermine online free shipping Compare ionamin phentermine Mastercard phentermine Fastin phentermine Medication drug mylan online search phentermine diet Fioricet description Tramadol active ingredient Phentermine about withdrawl Aldactone Viagra advertisement Methimazole Cleocin Buy viagra without a prescription Free viagra prescription Viagra compared to levivia Cefepime Viagra wholesale Soma side effects Xanax for sale Womans viagra Gemfibrozil Doxylamine Noroxin Hydrocodone picture Phentermine vs phentrazine Paregoric Phentermine 37.5 in round white tablets no imprint code Pentobarbital Phentermine without rx Online pharmacy phentermine cod Nitroglycerin and viagra Climara Perphenazine Altace Cialis dysfunction erectile levitra viagra Cheapest phentermine pills Compare viagra to cialis No prescription needed phentermine Pyridostigmine Phentermine drug interactions Luvox Delivery generic overnight viagra Meclizine 50mg viagra Xanax picture Flavoxate Next day delivery on phentermine Cope Phentermine success story Tramadol drug Seroquel Xanax xr Glyburide Viagra price online Droperidol Xanax withdrawl symptoms Viagra alternatives Imitrex Triazolam Lethal dose of xanax Beclomethasone Dulcolax Fill viagra prescription Meridia weight loss pill Ambien side effects Olanzapine Felbamate Phentermine prozac 10 min viagra Phentermine in stock ready to ship saturday delivery Phentermine overnight delivery no prescription Buy cod pay phentermine Trandolapril Delivery florida online pharmacy phentermine Vicodin overdose Amsterdam holland viagra Dexamethasone Viagra mexico Prescription phentermine with cod payment Clomipramine Crestor Teniposide Cialis dysfunction erectile levivia viagra Naltrexone Cialis levitra Cephradine Metformin Discount soma Viagra soft tabs Phentermine online Bulk phentermine Cialis dose Ticarcillin Phentermine delivered overnight Lunesta Buy tramadol without prescription Fluorescein Fosinopril Phentermine low price Carbenicillin Cordarone Vidarabine Tramadol medication Diovan Vicodin hp 2 mg xanax Levivia and viagra Phentermine sites that ship cash on delivery Cheap pharmacy viagra Fosamax Elavil Leflunomide Discount phentermine no prescription Soma addiction Phentermine dangers How long does phentermine stay in your system Can woman take viagra Ordering 30mg phentermine Oxycodone vs hydrocodone Ingredient phentermine Motrin Thioguanine Tramadol uses Soma cube 50 mg tramadol Tramadol ingredients Buying phentermine online Generic india viagra Lozol Pemoline Flovent What does phentermine do to your heart Isometheptene Link buy online viagra info domain Adipex diet discount phentermine pill Phentermine 30 mg Book hydrocodone sport Tramadol hcl 50mg Tramadol hydrochloride Phentermine addiction Tramadol dogs Alternative to viagra Tetrabenazine Cheap viagra pills Ramipril Plaquenil Viagra by mail Generic viagra online Ouabain Piperacetazine Fluorouracil Xanax libido Physostigmine Vicodin drug test Purchase cialis Buy Lipitor Probenecid Meridia vs. Phentermine Femara Hydrocodone apap 5 500 Tramadol 200 mg Fioricet with codeine Diclofenac Viagra samples free Phentermine accepts cod Chantix How much weight will you lose on phentermine Zafirlukast Side effects of drug xanax Xanax indications Vicodin Motrin Benazepril Xanax dose Free viagra sample Lexapro and phentermine Phentermine interactions Tramadol heath solutions network Phentermine without doctor's approval Best cialis price Cialis levitra viagra vs vs Fioricet order Phentermine ionamin canada Lowest price phentermine Generic viagra in canada Levivia viagra vs Free shipping with phentermine order Mivial valve prolapse viagra Androgel Viagra supplier Hydrocodone cod only Buy hydrocodone where Ciclopirox Benicar Midodrine Buy Soma Uk cheapest viagra Ethchlorvynol Glyburide Quinine Xanax withdrawel symptoms Woman using viagra Bosch power tools zio lowest viagra Cyclamate Hydrocodone Macrodantin Viagra ingredients Buy cialis without prescription Noctec Us pharmacy phentermine Xanax 2 mg Abacavir Xanax online without prescription Soma drug Buy online phentermine shipping Anisindione Phentermine without a perscription Bentyl Bontril phentermine adipex Viagra for women Soft cialis Sparfloxacin Nitric oxide viagra Phentermine 37 5mg Cheap generic viagra Viagra drug interaction Acetophenazine Quinethazone Topamax Indapamide Phentermine amide Sophia viagra Divalproex Dihydrotachysterol Prozac drug interaction with xanax Klonopin xanax Order viagra visit your doctor online University rochester viagra pfizer Cefuroxime Order soma carisoprodol Online pharmacy prescription viagra Doxycycline Tramadol hc Xanax withdrawals Thiopropazate Phentermine and ocular hypertension Tramadol 100 mg no prescription Drug test tramadol hydochloride Imipramine Isoxsuprine Buy xanax without prescription 100 tramadol Buy phentermine online prescription Ethanol Price viagra viacreme Cheap ambien Cheap phentermine no shipping Cialis compared to viagra Mepindolol Do companies sell phentermine with low dose ingredients Selegiline Cheap generic viagra substitutes Buy phentermine by cod Difference between cialis and viagra Melphalan Tramadol abuse Ceftizoxime Order phentermine by cod Method of payment accepted cod phentermine Does phentermine speed up metabolism Levofloxacin Allopurinol Woman take viagra Tramadol hcl 50 mg tab Cheap viagra in uk Arimidex Haldol Protonix Online pharmacy and phentermine Cialis levivia sales viagra Combivent Buy domain onlinebigsitecitycom phentermine Phenylpropanolamine Liothyronine Buy cialis generic online Soma Indapamide Lovastatin Female viagra uk Glucotrol Phenyltoloxamine Cialis company Order xanax Cheap online phentermine prescription Effects of phentermine Minocycline Nefazodone Ambien eminem Phentermine for sale Propantheline Moexipril Phentermine hcl Buy cheap domain online atspace com xanax Phentermine online pay with mastercard Buy phentermine mastercard Cialis price Phentermine success stories Alavert Adipex phentermine prescription Buy in phentermine uk Tramadol cheap Generic overnight viagra Adipex loss phentermine weight Phentermine hydrochloride Restoril Phentermine result I need to find cheap phentermine delivered to fl Estraderm Cocaine Mesoridazine Phentermine Fluticasone Phentermine message board Estrace Hydrocodone order Xanax side effect Azithromycin Herbal alternative to viagra Buy xanax no prescription Viagra testimony Viagra alternative herbal supplement Ambien coupon cr Bush inauguration speech draft viagra bastard of Chlorambucil Cardizem Order tramadol cod Levaquin Free try viagra Natural supplement for viagra Phentermine tolerance Cialis generic Proguanil Levivia vs viagra Buy pal pay phentermine using Terbinafine Safe internet shopping generic viagraeng Online pharmacy tramadol Cyclizine Levivia viagra Nortriptyline Guaifenesin Cheap tramadol cod free fedex Adipex p phentermine vs Xanax doses How long does xanax stay in your system Phendimetrazine versus phentermine Free shipping cheap phentermine Fioricet medication Paxil with phentermine interactions Buy viagra on line Labetalol Scopolamine Acetohexamide Suboxone Imiquimod Phentermine snorting Viagra erection Tacrolimus Viagra doseage Mark martin viagra photo Cialis vs viagra Canada generic viagra Drug interactions with cocaine and viagra Dapsone Custom hrt phentermine Time released phentermine Tramadol and dosage Xanax next day delivery Enoxaparin Metformin Phentermine hormone Lethal doses of klonopin and xanax Cheap cialis tablets Mercaptopurine Cialis generic viagra Bacitracin Viagra cream for woman Cialis impotence drug eli lilly co Fioricet Ambien rx Amerge Kanamycin Rofecoxib Xanax withdrawl message boards Online pharmacy viagra Pulmonary hypertension and viagra Venlafaxine Robaxin Buy buy domain link online online viagra info viag Adipex diet phentermine pill _achetez le viagra de levivia Buy phentermine in canada Iodoxamate Diet discount phentermine pill Buy com lvivhost online viagra Nizatidine Buy phentermine at amide pharmaceutical Viagra prescription online Wholesale pfizer viagra Aldara Diet medication online phentermine Viagra online order guide Avapro Iodine Phentermine hci Phentermine adipex Viagra usage Buy Tamiflu Anileridine Buy tramadol online Nialamide Viagra results Cialis uk Levitra Fioricet online Online tramadol prescriptions Macrobid Vicodin detox Long term side effects from xanax Hydrocodone Prozac and xanax induced mood disorder Online phentermine sale Phentermine saturday delivery Alendronate Buy cheap online viagra Estrogen Meloxicam Herbal phentermine forum Phentermine adipex diet pill discount Caverta veega generic viagra Piroxicam Meridia diet Lopressor Low cost cialis Methantheline Phentermine raleigh Order viagra buying viagra uk Pfizer xanax information Xanax suicide Bromides Coumarin Order xanax paying cod Atracurium Discount viagra online Cheap tramadol prescriptions online Lovenox Phentermine capsules Ethambutol Amaryl Cheap fioricet Xanax versus prozac Phentermine no rx needed Diet pal pay phentermine pill Sofia viagra Canada cheap viagra Cosopt Buy cialis in canada Gitalin Vinorelbine Erythrityl Dimethindene Ephedrine Actos phentermine aciphex imitrex Viagra prescription Hydrocodone overdose Clarinex Phentermine not working Generic viagra from india Demeclocycline Buy phentermine cod Sulfonamides Secobarbital Pill price viagra Xanax addiction Phentermine c.o.d. Tomorrow Pharmacy phentermine affiliate Viagra generic drug Oseltamivir Cialis levitra sales viagra Phentermine pharmacy cod Colchicine Phentermine versus meridia Purchase soma online Zidovudine Xanax drug interactions Paris cheep phentermine Metharbital Oxacillin Bontril Phentermine meridia xenical review Irbesartan Hydrocodone mexican pharmacy what is tramadol Ipodate Adipex phentermine xenical Get viagra online Ingredient in phentermine Effects from side viagra Lanoxin Elidel Cheapest viagra in uk Epinephrine

Entries Tagged 'Blogroll' ↓

See code, C code!

In writing a compiler, I’ve come across a sleek part of the standard c library that I just can’t help and a take a few minutes to write a blog post about it!

You can send any number of arguments to a method / macro that you want. It’s called Variadic methods and they have a crazy syntax. Here is a piece of code that I am using in the compiler. It’s super similar to the printf method (the printf method itself is a variadic method, if you’ve ever wondered…)


char *stringerize(const char *fmt, ...) {
	char *buf = safe_malloc(sizeof(char)*BUFSIZE);
	va_list args;

	va_start(args, fmt);
	if (args && strlen(args) > 0)
	  (void) vsnprintf(buf, BUFSIZE, fmt, args);
	va_end(args);

	return (buf);
}

Kind uninteresting, huh? I’ll show you a much more interesting one at the end of the post thatallows you to safely concatenate any number of strings.

The basic idea is that you define a method with the … syntax, such as


char *stringerize(const char *fmt, ...)
...

There are two two ways to access those variables.

One by one
First, you declare all your variables that you are going to use in the method. That has to be before accessing the list. Then, you start the list with


va_list args;

Make sure you don’t forget to declare the args as a list otherwise C will throw a fit.

Then, when you are ready to get the variables, call


va_start(args, fmt);

The second parameter is the last required argument in the command. You do need at least one required argument in a function. The same requirement does not hold true for macros, though.

Then, to get to the variable you call


va_arg(args, const char *);

The second parameter is the type you are expecting to come back. This gives C a heads up as to what to expect.

Then, when you are done and want to move on to the next one in the list, simply call:


va_end(args);

That’s it!

Accessing the variables all at once

You can either do this in a macro that would look something like (untested):


#define VARGS(...) fprintf(stderr, __VA_ARGS__)
// or
#define VARGS(fmt, args...) fprintf(stderr, fmt, args)

There are other ways as well, but those are the ones that stood out to me. In a method, you can do this as I had done in the example above. Just call list and all the arguments are accessible to you, right there in your shirt pocket!

And now, finally for the more important snippet that:


char *concat_commands(const char* str,...) {
	va_list args; char *s; size_t held_memory = 100;
	char *res = safe_malloc(sizeof(char)*held_memory);
	if (res != NULL) {
		char *new_pointer, *word_pointer;
		va_start(args, str);
		word_pointer = res;
		for (s=str;s!=NULL;s=va_arg(args, const char *)) {
			size_t len = strlen(s);
			if (word_pointer + len + 1 > res + held_memory) {
				held_memory = (held_memory + len) * 2;
				new_pointer = (char *) realloc (res, held_memory);
				if (new_pointer == NULL) { free(res); return NULL; }
				word_pointer = new_pointer + (word_pointer - res);
				res = new_pointer;
			}
			word_pointer = memcpy(word_pointer,s,len);
			word_pointer = word_pointer + len;
		}
		*word_pointer++ = '';
		new_pointer = (char *) realloc(res, word_pointer-res);
		if (new_pointer != NULL) {res = new_pointer;}
		va_end(args);
	}
	return res;
}

I hope this helps someone out there save a few hours and remember how cool C even in the midst of the ruby we all love so much. On that note, I urge you to look at the ruby interpreter source code. It’s a tad jumbled up, my guess is because there are a few people working on it, but it is sure damn sexy code. Thanks once again matz!

I’ll be back more in a week or so for more fervent posts after my compiler is done.

More information here

ActiveRecord fun (basics of both callbacks and overloading)

Have you ever found yourself writing a code similar to this

[source:ruby]
class Post < ActiveRecord::Base

has_one :image

def get_image
image_id.nil? ? Image.default_image : Image.find(image_id)
end

end
[/source]

Where you have an instance where rather than catching an AR Exception, you want to have a default value for a model?

I noticed I was writing code like this, all the time

[source:ruby]
def get_image
begin
Image.find(params[:id])
rescue Exception => e
Image.default_image
end
end
[/source]

Imagine that, all over the place. How ugly!

So, rather than continue with this semi-ruby-style code, let’s use ActiveRecord and create ourselves a fun 20 minutes creating a fallback.

Let’s get started.

First things first, I like to place things in modules to separate the different methods, you may have your own thing, but… this is my article so I’ll tell you what works for me:

I usually start with a basic template when I am either a) creating a plugin that will extend an object or b) creating a file that will extend an object.

[source:ruby]
module CitrusByte
module ARFinderExtensions
def self.included(receiver)
receiver.extend MeatMethods
end

module MeatMethods
def something_here(*args)
extend CitrusByte::ARFinderExtensions::ClassMethods
include CitrusByte::ARFinderExtensions::InstanceMethods
end
end

module ClassMethods
end
module InstanceMethods
end
end
end
end
[/source]

In case you’ve never seen this schtuff before, it’s pretty cool. Check out the ruby docs for more information, but in a nutshell, if you place the something_here method inside a class, then that class with have the class methods and the instances will have the instance methods. It’s that simple. Check out the acts_as plugins. This is how they do it.

Anyways, so we have the basic template, now let’s fill some stuff in and get our find missing stuff moved into place.

Before we go any further, in my extensions, I am going to use a callback. This way we can have methods that operate at the class level and are defined on the instance and the two can fit seamlessly together.

So, what is a callback? Don’t tell me you haven’t used a callback before. The before_save, after_create methods are all callbacks that we use and take for granted as rails developers daily. Well, what are they already?

Callbacks are nothing more than attr_accessors that are accessible on the entire hierarchy of the instance. The difference is that the accessor in a callback is not the same as the one “owned” by the parent.

So now, we are going to use that to our advantage and define our own callback.

Time for some code (Going back to the example above… ):

[source:ruby]
def self.included(receiver)
receiver.extend MeatMethods
receiver.class_eval do
class << self
alias_method_chain :find, :catch
end
# Add the callback
def self.rescue_not_found(*callbacks, &block)
callbacks << block if block_given?
write_inheritable_array(:rescue_not_found, [block])
end
end
end
[/source]

Whenever any module is included into a class, the included method is called on the module. It’s ruby’s ultra-useful callback on itself. We can use it to do some really funky neat stuff. Can you think of other things we can use it for?

line 1 extends the MeatMethods (which we will deal with later) to the object
line 2 evaluates the block at the class level
lines 3-5 places inside the class, the ability to extend the instance with a class variable (confusing? Jay Fields has some awesome thoughts about this he hashes out Here) and alias_method_chain’s the methods find and catch.
If you don’t know what alias_method_chain does, ooo it’s slick. Basically it adds two methods to the class (first _with_ second AND first _without_ second) at hand and calls them in order. Wha? Meaning… for our circumstance, it will add find_with_catch and find_without_catch! How cool
line 7-10 have to do with the callbacks. First off, the callback name is going to be rescue_not_found. It is described as a block (as you are used to) and appends it , a block or not on to the inheritable_array.

How cool! I hope you are having fun, I sure am.

Now let’s actually add a method:

[source:ruby]
def find_with_catch(*args)
options = args.extract_options!
validate_find_options(options)
set_readonly_option!(options)

begin
case args.first
when :first then find_initial(options)
when :all then find_every(options)
else find_from_ids(args, options)
end
rescue Exception => e
callback :rescue_not_found
end
[/source]

This is basically the rails way of handling a find method with two major differences. First, this is the find_with_catch method that we defined above. Second, there is the rescue part which is what will be doing our work for us. Notice the rescue:

[source:ruby]
rescue Exception => e
callback :rescue_not_found
end
[/source]

If the ActiveRecord::Base#find can’t find an associated object in the database, it will throw a RecordNotFoundException… but in our scenario, we don’t want that… we want to have a method called instead, the entire point of our adventure! So we are going to catch that exception and instead, call the defined callback rescue_not_found.

There are a few more unimportant methods on the module, so I’ll skip those for now and you can check them out (including the callback method), but the one last important tidbit that you will need to know if you are going to use this fun-ness is that you actually have to add this stuff to ActiveRecord somehow… depending on the context, you could call the method defined above or just include it to the base…

For us, in this circumstance, we’ll use
[source:ruby]
ActiveRecord::Base.send(:include, CitrusByte::ARFinderExtensions)
[/source]

’cause we want all the finds to call the callback!

This allows you to do something like:

[source:ruby]
class Image < ActiveRecord::Base
rescue_not_found do
Image.new {:id => 1, :filename => “no_image.jpg”}.freeze
end
end
[/source]

This is much nicer than the former where a find had to be nested inside a begin;rescue;end statement.

Let me know how this works for you!

Also, you should stay tuned! Some big things are just on the horizon. I have a few plugins I am going to release here in a few days, I have a new blog posting coming out shortly too about rmagick and it’s use in production and I have a stellar joke in the mix too! That’s not all, but that’s I’ll I will say for now ;)

active_record_extensions.rb