Sha256: 829a27cbb185ea24a293317dc8a20f49332709241735f2ab4b252464101a3ced
Contents?: true
Size: 888 Bytes
Versions: 8
Compression:
Stored size: 888 Bytes
Contents
module INE::Places::CSVRecord extend ::ActiveSupport::Concern def to_param self.slug end class_methods do def all collection_klass.records end def find_by_name(name) raise ArgumentError if name.blank? records_by_name[name] end def find_by_slug(slug) raise ArgumentError if slug.blank? records_by_slug[slug] end def find(id) raise ArgumentError if id.blank? records_by_id[id.to_i] end private def records_by_id @records_by_id ||= Hash[collection_klass.records.map{ |record| [record.id.to_i, record] }] end def records_by_slug @records_by_slug ||= Hash[collection_klass.records.map{ |record| [record.slug, record] }] end def records_by_name @records_by_name ||= Hash[collection_klass.records.map{ |record| [record.name, record] }] end end end
Version data entries
8 entries across 8 versions & 1 rubygems