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 Delegation::DelegateCache

#inherited, #initialize_relation_delegate_cache, #relation_delegate_class

Methods included from Reflection

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.



56
57
58
# File 'lib/active_any/base.rb', line 56

def file
  @file
end

Class Method Details

.adapterObject



78
79
80
# File 'lib/active_any/base.rb', line 78

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

.dataObject



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

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

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

.reloadObject



73
74
75
76
# File 'lib/active_any/base.rb', line 73

def reload
  @data = nil
  data
end