Class: Lolita::Adapter::Mongoid::Field

Inherits:
Object
  • Object
show all
Includes:
FieldHelper
Defined in:
lib/lolita/adapter/mongoid.rb

Overview

Each field from ORM is changed to this class instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FieldHelper

#content?, #technical?

Constructor Details

#initialize(column, adapter) ⇒ Field

Returns a new instance of Field.

Raises:

  • (ArgumentError)


69
70
71
72
73
74
# File 'lib/lolita/adapter/mongoid.rb', line 69

def initialize(column,adapter)
  @field = column
  raise ArgumentError, "Cannot initialize adapter field for nil" unless @field
  @adapter = adapter
  set_attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



90
91
92
# File 'lib/lolita/adapter/mongoid.rb', line 90

def method_missing(method,*args,&block)
  @field.send(method,*args,&block)
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



68
69
70
# File 'lib/lolita/adapter/mongoid.rb', line 68

def adapter
  @adapter
end

#fieldObject (readonly)

Returns the value of attribute field.



68
69
70
# File 'lib/lolita/adapter/mongoid.rb', line 68

def field
  @field
end

#nameObject (readonly)

Returns the value of attribute name.



68
69
70
# File 'lib/lolita/adapter/mongoid.rb', line 68

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



68
69
70
# File 'lib/lolita/adapter/mongoid.rb', line 68

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



68
69
70
# File 'lib/lolita/adapter/mongoid.rb', line 68

def type
  @type
end

Instance Method Details

#associationObject



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/lolita/adapter/mongoid.rb', line 76

def association
  if @association.nil?
    possible_association = @adapter.associations.detect{|name,association|
      [association.key.to_s].include?(@name.to_s)
    }
    @association = if possible_association
      possible_association.last
    else
      false
    end
  end
  @association
end

#primary?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/lolita/adapter/mongoid.rb', line 94

def primary?
  !!self.options[:primary] || @field.type.to_s =~ /ObjectId/
end