Class: Yaoc::NormalizedParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/yaoc/converter_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to, from, converter, object_converter, is_collection, lazy_loading) ⇒ NormalizedParameters

Returns a new instance of NormalizedParameters.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/yaoc/converter_builder.rb', line 6

def initialize(to, from, converter, object_converter, is_collection, lazy_loading)
  self.to_s = Array(to)
  self.from_s = Array(from)
  self.converter_s = Array(converter)
  self.lazy_loading_s = Array(lazy_loading)

  object_converter_s = Array(object_converter)
  is_collection_s = Array(is_collection)

  self.to_s.each_with_index do |to, index|
    from_s[index] ||= to
    lazy_loading_s[index] ||= false
  end

  object_converter_s.each_with_index do |object_converter, index|
    converter_s[index] = converter_to_proc(to_s[index],
                                           from_s[index],
                                           object_converter,
                                           !!is_collection_s[index],
                                           !!lazy_loading_s[index])
  end

end

Instance Attribute Details

#converter_sObject

Returns the value of attribute converter_s.



4
5
6
# File 'lib/yaoc/converter_builder.rb', line 4

def converter_s
  @converter_s
end

#from_sObject

Returns the value of attribute from_s.



4
5
6
# File 'lib/yaoc/converter_builder.rb', line 4

def from_s
  @from_s
end

#lazy_loading_sObject

Returns the value of attribute lazy_loading_s.



4
5
6
# File 'lib/yaoc/converter_builder.rb', line 4

def lazy_loading_s
  @lazy_loading_s
end

#to_sObject

Returns the value of attribute to_s.



4
5
6
# File 'lib/yaoc/converter_builder.rb', line 4

def to_s
  @to_s
end

Instance Method Details

#converter_to_proc(to, from, converter, is_collection, deferred) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yaoc/converter_builder.rb', line 38

def converter_to_proc(to, from, converter, is_collection, deferred)
  ->(source, result){
    get_value_with = ->{
      object_to_convert = source.public_send(fetcher, from)

      if is_collection
        object_to_convert.map(&converter)
      else
        converter_as_proc = converter.to_proc
        converter_as_proc.call(object_to_convert)
      end
    }

    fill_result_from_proc(result, to, get_value_with, deferred)
  }
end

#eachObject



30
31
32
33
34
35
36
# File 'lib/yaoc/converter_builder.rb', line 30

def each
  return to_enum(__callee__) unless block_given?

  self.to_s.each_with_index do |to, index|
    yield to, from_s[index] , converter_s[index], lazy_loading_s[index]
  end
end