Class: ActiveAny::CSV

Inherits:
Base
  • Object
show all
Defined in:
lib/active_any/base.rb

Defined Under Namespace

Classes: MissingFileError

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Reflection

_reflect_on_association, add_reflection, create

Methods included from AttributeAssignment

#assign_attributes, #init_internals

Methods included from Associations

#association, #initialize_dup

Methods included from Attribute

#attribute_for_inspect, #attributes, #has_attribute?, #inspect, #read_attribute

Methods included from Core

#[], #initialize

Class Attribute Details

.fileObject

Returns the value of attribute file.



58
59
60
# File 'lib/active_any/base.rb', line 58

def file
  @file
end

Class Method Details

.adapterObject



80
81
82
# File 'lib/active_any/base.rb', line 80

def adapter
  @adapter ||= ObjectAdapter.new(self)
end

.dataObject



66
67
68
69
70
71
72
73
# File 'lib/active_any/base.rb', line 66

def data
  @data ||= begin
    raise MissingFileError unless file

    table = ::CSV.table(file)
    table.map { |row| new(row.to_h) }
  end
end

.reloadObject



75
76
77
78
# File 'lib/active_any/base.rb', line 75

def reload
  @data = nil
  data
end