Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/utils.rb,
lib/horrible_hack.rb
Direct Known Subclasses
Ig3tool::BibBook, Ig3tool::BibLoan, Ig3tool::BibSection, Ig3tool::Bitch, Ig3tool::Category, Ig3tool::Interne, Ig3tool::InterneTransaction, Ig3tool::LogEntry, Ig3tool::Membership, Ig3tool::Person, Ig3tool::PrintAlias, Ig3tool::PrintTransaction, Ig3tool::PrintUser, Ig3tool::Product, Ig3tool::Purchase, Ig3tool::Request, Ig3tool::Sale
Class Method Summary collapse
- .hash_lookup(search, valid_keys) ⇒ Object
-
.set_nonauto_primary_key(field) ⇒ Object
Deze methode laat toe TOCH primary keys te hebben.
Instance Method Summary collapse
Class Method Details
.hash_lookup(search, valid_keys) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/utils.rb', line 82 def self.hash_lookup(search, valid_keys) search = search.to_h unless search.is_a? Hash return find(:all) if search.empty? clauses = [] values = [] search.normalize_keys! { |k| k.to_s.downcase } search.each do |k, v| raise "Invalid search key '#{k}'" unless valid_keys.include? k if %w(barcode username).include? k or k == primary_key clauses << "#{k} = ?" values << v else clauses << "#{k} like ?" v = "%#{v}%" values << v end end find(:all, :conditions => [ clauses.join(" AND "), *values ]) end |
.set_nonauto_primary_key(field) ⇒ Object
Deze methode laat toe TOCH primary keys te hebben.
4 5 6 7 8 |
# File 'lib/horrible_hack.rb', line 4 def self.set_nonauto_primary_key(field) set_primary_key field define_method (field.to_s+"_before_type_cast").to_sym do; end alias_method field.to_s+"=", :id= end |
Instance Method Details
#attributes_protected_by_default ⇒ Object
10 11 12 |
# File 'lib/horrible_hack.rb', line 10 def attributes_protected_by_default [] # STERF. end |