lib/mongoid/fields.rb in mongoid-1.9.5 vs lib/mongoid/fields.rb in mongoid-2.0.0.alpha
- old
+ new
@@ -1,19 +1,16 @@
# encoding: utf-8
module Mongoid #:nodoc
module Fields #:nodoc
- def self.included(base)
- base.class_eval do
- extend ClassMethods
- # Set up the class attributes that must be available to all subclasses.
- # These include defaults, fields
- class_inheritable_accessor :fields
+ extend ActiveSupport::Concern
+ included do
+ # Set up the class attributes that must be available to all subclasses.
+ # These include defaults, fields
+ class_inheritable_accessor :fields
- self.fields = {}
-
- delegate :defaults, :fields, :to => "self.class"
- end
+ self.fields = {}
+ delegate :defaults, :fields, :to => "self.class"
end
module ClassMethods #:nodoc
# Defines all the fields that are accessable on the Document
# For each field that is defined, a getter and setter will be
@@ -45,10 +42,9 @@
# Define a field attribute for the +Document+.
def set_field(name, options = {})
meth = options.delete(:as) || name
fields[name] = Field.new(name, options)
create_accessors(name, meth, options)
- add_dirty_methods(name)
end
# Create the field accessors.
def create_accessors(name, meth, options = {})
define_method(meth) { read_attribute(name) }