ginjo RFM NoMethodError:未定义的方法`name'哈希

时间:2014-05-09 07:09:55

标签: ruby-on-rails gem

我们发现ginjo RFM Gem(https://github.com/ginjo/rfm)存在间歇性问题。这没有多大意义。

想知道是否有人可以对此有所了解。

错误是

NoMethodError: undefined method name' for {"name"=>"addr_full", "data"=>{"__content__"=>" NSW "}}:Hash /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:129:inrescue in block in initialize'
/data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:129:in block in initialize' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:127:ineach'
/data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:127:in initialize' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/base.rb:111:innew'
/data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/base.rb:111:in rescue in new' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/base.rb:108:innew'
/data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-2.1.7/lib/rfm/record.rb:171:in block in build_records' /data/myi/shared/bundled_gems/ruby/2.0.0/gems/ginjo-rfm-

Ginjo RFM使用名为.name的方法扩展Hash,问题是“有时”方法不存在,但我们无法解决原因。 Ginjo RFM代码有这个方法

RFM代码执行此操作

 record.columns.each do |field|
        next unless field
           field_name = @layout.field_mapping[field.name] || field.name rescue field.name

field.name是个问题。我们认为可行的黑客是

rescue field['name']

注意:字段是哈希。这已经用名称方法扩展 他们通过覆盖record.columns上的.each方法来实现这一点,其中包含以下扩展哈希的方法。

 def rfm_extend_members(klass, caller=nil)
    @parent = caller
    @root = caller.instance_variable_get(:@root)
    @member_extension = klass
    self.instance_eval do
      class << self
        attr_accessor :parent

            alias_method 'old_reader', '[]'
            def [](*args)
                member = old_reader(*args)
          rfm_extend_member(member, @member_extension, args[0]) if args[0].is_a? Integer
                member
            end

            alias_method 'old_each', 'each'
            def each
                i = -1
                old_each do |member|
                    i = i + 1
                    rfm_extend_member(member, @member_extension, i)
                    yield(member)
                end
            end
      end
    end unless defined? old_reader
    self
  end

  def rfm_extend_member(member, extension, i=nil)
    if member and extension
        unless member.instance_variable_get(:@root)
              member.instance_variable_set(:@root, @root)
              member.instance_variable_set(:@parent, self)
              member.instance_variable_set(:@index, i)
            member.instance_eval(){def root; @root; end}
            member.instance_eval(){def parent; @parent; end}
            member.instance_eval(){def get_index; @index; end}
        end
            member.extend(extension)
        end  
  end

他们正在使用

扩展Hash
module Column
        def name
            #n = parent.index {|i| i === self}
            root.fields[get_index].name             
        end

        def data
            self['DATA'].rfm_force_array.collect{|d| d['__content__']}
        end
    end

我完全不明白为什么这有时会起作用,有时候不行。在我们的生产环境中,负载似乎更糟。

还困惑为什么他们首先这样做了。但那是个问题:)

有什么建议吗?

0 个答案:

没有答案