Class: CsvRowModel::Import::Representation

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_row_model/internal/import/representation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, row_model) ⇒ Representation


6
7
8
9
10
# File 'lib/csv_row_model/internal/import/representation.rb', line 6

def initialize(name, options, row_model)
  @name = name
  @options = options
  @row_model = row_model
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


4
5
6
# File 'lib/csv_row_model/internal/import/representation.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


4
5
6
# File 'lib/csv_row_model/internal/import/representation.rb', line 4

def options
  @options
end

#row_modelObject (readonly)

Returns the value of attribute row_model


4
5
6
# File 'lib/csv_row_model/internal/import/representation.rb', line 4

def row_model
  @row_model
end

Class Method Details

.define_lambda_method(row_model_class, representation_name, &block) ⇒ Object


51
52
53
# File 'lib/csv_row_model/internal/import/representation.rb', line 51

def define_lambda_method(row_model_class, representation_name, &block)
  row_model_class.define_proxy_method(lambda_name(representation_name), &block)
end

.lambda_name(representation_name) ⇒ Object


47
48
49
# File 'lib/csv_row_model/internal/import/representation.rb', line 47

def lambda_name(representation_name)
  :"__#{representation_name}"
end

.valid_optionsObject


55
56
57
# File 'lib/csv_row_model/internal/import/representation.rb', line 55

def valid_options
  %i[memoize empty_value dependencies]
end

Instance Method Details

#dependenciesObject


42
43
44
# File 'lib/csv_row_model/internal/import/representation.rb', line 42

def dependencies
  Array(options[:dependencies])
end

#dependencies_valueObject


24
25
26
# File 'lib/csv_row_model/internal/import/representation.rb', line 24

def dependencies_value
  valid_dependencies? ? lambda_value : empty_value
end

#empty_valueObject


34
35
36
# File 'lib/csv_row_model/internal/import/representation.rb', line 34

def empty_value
  options[:empty_value]
end

#lambda_valueObject


38
39
40
# File 'lib/csv_row_model/internal/import/representation.rb', line 38

def lambda_value
  row_model.public_send(self.class.lambda_name(name))
end

#memoize?Boolean


20
21
22
# File 'lib/csv_row_model/internal/import/representation.rb', line 20

def memoize?
  options.has_key?(:memoize) ? !!options[:memoize] : true
end

#memoized_valueObject


16
17
18
# File 'lib/csv_row_model/internal/import/representation.rb', line 16

def memoized_value
  @memoized_value ||= dependencies_value
end

#valid_dependencies?Boolean


29
30
31
32
# File 'lib/csv_row_model/internal/import/representation.rb', line 29

def valid_dependencies?
  dependencies.each { |attribute_name| return false if row_model.public_send(attribute_name).blank? }
  true
end

#valueObject


12
13
14
# File 'lib/csv_row_model/internal/import/representation.rb', line 12

def value
  memoize? ? memoized_value : dependencies_value
end