module CsvRecord::Reader::ClassMethods

Constants

DYNAMIC_FINDER_PATTERN

Public Instance Methods

__count__() click to toggle source
# File lib/csv_record/reader.rb, line 45
def __count__
  open_database_file do |csv|
    csv.entries.size
  end
end
Also aliased as: count
__doppelganger_fields__() click to toggle source
# File lib/csv_record/reader.rb, line 27
def __doppelganger_fields__
  __fields__.map(&:doppelganger)
end
Also aliased as: doppelganger_fields
__fields__() click to toggle source
# File lib/csv_record/reader.rb, line 23
def __fields__
  @fields ||= ::CsvRecord::Fields.new
end
Also aliased as: fields
__find__(condition) click to toggle source
# File lib/csv_record/reader.rb, line 51
def __find__(condition)
  (__where__ id: condition.to_param).first
end
Also aliased as: find
__where__(params) click to toggle source
# File lib/csv_record/reader.rb, line 55
def __where__(params)
  ::CsvRecord::Query.new self, params
end
Also aliased as: where
all() click to toggle source
# File lib/csv_record/reader.rb, line 31
def all
  open_database_file do |csv|
    csv.entries.map(&method(:build))
  end
end
build(params={}) { |inst| ... } click to toggle source
# File lib/csv_record/reader.rb, line 9
def build(params={})
  new.tap do |inst|
    break unless params

    params.each do |key, value|
      attribute = fields.find_with_doppelganger(key)
      attr_name = attribute ? attribute.name : key
      inst.public_send "#{attr_name}=", value
    end

    yield inst if block_given?
  end
end
first() click to toggle source
# File lib/csv_record/reader.rb, line 37
def first
  all.first
end
last() click to toggle source
# File lib/csv_record/reader.rb, line 41
def last
  all.last
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/csv_record/reader.rb, line 59
def method_missing(meth, *args, &block)
  if meth.to_s =~ DYNAMIC_FINDER_PATTERN
    dynamic_finder $1, *args, &block
  else
    super
  end
end
respond_to?(meth) click to toggle source
Calls superclass method
# File lib/csv_record/reader.rb, line 67
def respond_to?(meth)
  (meth.to_s =~ DYNAMIC_FINDER_PATTERN) || super
end

Private Instance Methods

count()
Alias for: __count__
doppelganger_fields()
dynamic_finder(meth, *args, &block) click to toggle source
# File lib/csv_record/reader.rb, line 73
def dynamic_finder(meth, *args, &block)
  properties = meth.split '_and_'
  conditions = Hash[properties.zip args]
  __where__(conditions).first
end
fields()
Alias for: __fields__
find(condition)
Alias for: __find__
where(params)
Alias for: __where__