Class: Mongoid::Orderable::Generators::Position

Inherits:
Base
  • Object
show all
Defined in:
lib/mongoid/orderable/generators/position.rb

Instance Attribute Summary

Attributes inherited from Base

#klass

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Mongoid::Orderable::Generators::Base

Instance Method Details

#generate(field_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mongoid/orderable/generators/position.rb', line 7

def generate(field_name)
  klass.class_eval <<~KLASS, __FILE__, __LINE__ + 1
    def orderable_position(field = nil)
      field ||= default_orderable_field
      send("orderable_\#{field}_position")
    end
  KLASS

  generate_method("orderable_#{field_name}_position") do
    send(field_name)
  end

  generate_method("orderable_#{field_name}_position=") do |value|
    send("#{field_name}=", value)
  end
end