Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
Created March 2, 2011 16:28
Show Gist options
  • Save pullmonkey/851207 to your computer and use it in GitHub Desktop.
Save pullmonkey/851207 to your computer and use it in GitHub Desktop.
module Pickle
module Session
def find_latest_model(a_model_name, fields = nil)
factory, name = *parse_model(a_model_name)
raise ArgumentError, "Can't find a model with an ordinal (e.g. 1st user)" if name.is_a?(Integer)
model_class = pickle_config.factories[factory].klass
fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
conditions = convert_models_to_attributes(model_class, fields)
# Aside from method names, this is the line that changed, everything else is the same
record = Pickle::Adapter.find_first_model(model_class, conditions).class.send(:last)
store_model(factory, name, record) if record
record
end
def find_latest_model!(name, fields = nil)
find_latest_model(name, fields) or raise ModelNotKnownError, name
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment