Class: Drupal::CCK::ThroughField

Inherits:
Object
  • Object
show all
Defined in:
lib/drupal/cck/fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ ThroughField

Returns a new instance of ThroughField.



12
13
14
15
# File 'lib/drupal/cck/fields.rb', line 12

def initialize field
  self.table = field
  self.field_name = field.match(/^content_field_(.*)/)[1]
end

Instance Attribute Details

#field_nameObject

Returns the value of attribute field_name.



10
11
12
# File 'lib/drupal/cck/fields.rb', line 10

def field_name
  @field_name
end

#tableObject

Returns the value of attribute table.



10
11
12
# File 'lib/drupal/cck/fields.rb', line 10

def table
  @table
end

Instance Method Details

#fieldObject



17
18
19
# File 'lib/drupal/cck/fields.rb', line 17

def field
  @field ||= ContentNodeField.first :field_name => "field_#{field_name}"
end

#field_typeObject



25
26
27
28
29
30
31
32
# File 'lib/drupal/cck/fields.rb', line 25

def field_type
  case field.type
  when 'userreference'
    "belongs_to :user,
      :class_name => 'Drupal::User',
      :child_key => [:#{field.field_name}_uid]"
  end
end

#to_sObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/drupal/cck/fields.rb', line 34

def to_s
  return "" unless valid?
  "
    class #{field_name.camel_case}
      #{Drupal.common}
      storage_names[:drupal] = '#{table}'
      
      property :vid, Integer, :key => true
      belongs_to :node,
        :class_name => 'Drupal::Node',
        :child_key => [:nid]
      Drupal::User
      #{field_type}
    end
  "
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/drupal/cck/fields.rb', line 21

def valid?
  !field.nil?
end