module NoBrainer::Document::PrimaryKey::ClassMethods
Public Instance Methods
define_default_pk()
click to toggle source
# File lib/no_brainer/document/primary_key.rb, line 41 def define_default_pk class_variable_set(:@@pk_name, nil) # TODO Maybe we should let the user configure the pk generator pk_generator = NoBrainer::Document::PrimaryKey::Generator field NoBrainer::Document::PrimaryKey::DEFAULT_PK_NAME, :primary_key => true, :type => pk_generator.field_type, :default => ->{ pk_generator.generate } end
field(attr, options={})
click to toggle source
Calls superclass method
# File lib/no_brainer/document/primary_key.rb, line 51 def field(attr, options={}) return super unless options[:primary_key] if attr != pk_name remove_field(pk_name, :set_default_pk => false) if pk_name class_variable_set(:@@pk_name, attr) end options[:index] = true options[:readonly] = true super end
pk_name()
click to toggle source
# File lib/no_brainer/document/primary_key.rb, line 37 def pk_name class_variable_get(:@@pk_name) end
remove_field(attr, options={})
click to toggle source
Calls superclass method
# File lib/no_brainer/document/primary_key.rb, line 64 def remove_field(attr, options={}) if fields[attr][:primary_key] && options[:set_default_pk] != false define_default_pk end super end