Class: Lolita::Adapter::ActiveRecord::Field

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

Overview

Each field from ORM is changed to this class instance.

Instance Attribute Summary collapse

Class Method 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)


84
85
86
87
88
89
# File 'lib/lolita/adapter/active_record.rb', line 84

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



109
110
111
# File 'lib/lolita/adapter/active_record.rb', line 109

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

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



83
84
85
# File 'lib/lolita/adapter/active_record.rb', line 83

def adapter
  @adapter
end

#fieldObject (readonly)

Returns the value of attribute field.



83
84
85
# File 'lib/lolita/adapter/active_record.rb', line 83

def field
  @field
end

#nameObject (readonly)

Returns the value of attribute name.



83
84
85
# File 'lib/lolita/adapter/active_record.rb', line 83

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



83
84
85
# File 'lib/lolita/adapter/active_record.rb', line 83

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



83
84
85
# File 'lib/lolita/adapter/active_record.rb', line 83

def type
  @type
end

Class Method Details

.typesObject



117
118
119
120
121
122
123
# File 'lib/lolita/adapter/active_record.rb', line 117

def self.types
  {
    'decimal' => 'big_decimal',
    'datetime' => 'date_time',
    'text' => 'string'
  }
end

Instance Method Details

#associationObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/lolita/adapter/active_record.rb', line 91

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

#keyObject



105
106
107
# File 'lib/lolita/adapter/active_record.rb', line 105

def key
  @association.foreign_association_key
end

#primary?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/lolita/adapter/active_record.rb', line 113

def primary?
  !!self.options[:primary]
end