Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4352

override setter methods for field names with spaces

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: 4.0.0 final
    • Component/s: None
    • None
    • Environment:
      Linux, Mac, etc

      I have a MongoDB field with spaces, something like 'Hello World'. I am able to do the following:

      class MyDocument
      include Mongoid::Document
      end

      _field = 'Hello World'

      MyDocument.class_eval <<-EOS
      field :'#

      { _field }', type: #{_type}
      EOS

      But I need to override the setter of the field. And the below options do not work:

      MyDocument.class_eval <<-EOS
      def #{ _field }

      =(val)
      self['#

      { _field }'] = [self.send('#{ _field }

      ')[0], val]
      end
      EOS

      MyDocument.instance_eval do
      define_method _field do |val|
      super([self.send(_field)[0], val])
      end
      end

      How am I supposed to override the setter of the field?

            Assignee:
            Unassigned Unassigned
            Reporter:
            johnmerlino John Merlino
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: