Class: Mappum::DSL::FieldMap

Inherits:
Map show all
Defined in:
lib/mappum/dsl.rb

Instance Attribute Summary collapse

Attributes inherited from Map

#def

Instance Method Summary collapse

Methods inherited from Map

#`, #const, #context, #func, #map, #map_when, #name_map, #name_map_prefix, #to_array_take, #tree

Constructor Details

#initialize(*attr) ⇒ FieldMap

Returns a new instance of FieldMap.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/mappum/dsl.rb', line 160

def initialize(*attr)
  @def = Mappum::FieldMap.new
  type_size = 1
  if attr == [[nil]]
    raise """Can't make map for [[nil]] arguments. 
    Can be that You define top level class mapping with \"<=>\" please use \",\" instead (we know its a Bug). """
  end
  mapped = attr[0][0]
  if attr[0][0].instance_of?(Class) or attr[0][0].instance_of?(Symbol) and
         attr[0][1].instance_of?(Class) or attr[0][1].instance_of?(Symbol)
     mapped = [attr[0][0], attr[0][1]]
     type_size = 2   
  end
  
  if mapped.instance_of?(Array) then
    if(mapped[0]).instance_of?(Class) or (mapped[0]).instance_of?(Symbol)
      @def.strip_empty = false
      self.mpun_left = Field.new(nil,nil,mapped[0])
    else
      self.mpun_left = mapped[0]
    end
    if(mapped[1]).instance_of?(Class) or (mapped[1]).instance_of?(Symbol)
      @def.strip_empty = false
      self.mpun_right = Field.new(nil,nil,mapped[1])
    else
      self.mpun_right = mapped[1]
    end
  end
  if mapped.instance_of?(Hash) then
    self.mpun_left = mapped.keys[0]
    self.mpun_right = mapped.values[0]
  end
  
  if mapped.instance_of?(Hash) then
    @def.from = @def.left
    @def.to = @def.right
  end

  @def.dict = attr[0][1][:dict] if attr[0].size > type_size
  @def.desc = attr[0][1][:desc] if attr[0].size > type_size
  @def.map_when = attr[0][1][:when] if attr[0].size > type_size
  @def.when_r2l = attr[0][1][:when_r2l] if attr[0].size > type_size
  @def.when_l2r = attr[0][1][:when_l2r] if attr[0].size > type_size
  if @def.normalized? and not (@def.when_r2l.nil? and  @def.when_l2r.nil?)
    raise "r2l and l2r :when functions can be set only on bidirectional maps"  
  end
  if not @def.normalized? and not @def.map_when.nil?
    raise ":when function can be set only on unidirectional maps use :when_r2l and :when_l2r or map_when function"  
  end
  @def.to_array_take = attr[0][1][:to_array_take] if attr[0].size > type_size
  if not @def.normalized? and not @def.to_array_take.nil?
    raise ":to_array_take property can be set only on unidirectional maps use :to_array_take_r2l and :to_array_take_l2r or to_array_take function"  
  end
  @def.submap_alias = attr[0][1][:map] if attr[0].size > type_size
              
end

Instance Attribute Details

#mpun_leftObject

Returns the value of attribute mpun_left.



151
152
153
# File 'lib/mappum/dsl.rb', line 151

def mpun_left
  @mpun_left
end

#mpun_rightObject

Returns the value of attribute mpun_right.



151
152
153
# File 'lib/mappum/dsl.rb', line 151

def mpun_right
  @mpun_right
end