Class: Drupal::CCK::Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_type) ⇒ Table

Returns a new instance of Table.



34
35
36
# File 'lib/drupal/cck/builder.rb', line 34

def initialize content_type
  self.content_type = content_type
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



32
33
34
# File 'lib/drupal/cck/builder.rb', line 32

def content_type
  @content_type
end

Instance Method Details

#columnsObject



46
47
48
# File 'lib/drupal/cck/builder.rb', line 46

def columns
  @columns ||= fields
end

#fieldsObject



42
43
44
# File 'lib/drupal/cck/builder.rb', line 42

def fields
  Drupal::CCK::ContentNodeFieldInstance.all :content_type => content_type
end

#ignore_columnsObject



50
51
52
# File 'lib/drupal/cck/builder.rb', line 50

def ignore_columns
  %w{nid vid}
end

#tableObject



38
39
40
# File 'lib/drupal/cck/builder.rb', line 38

def table
  "content_type_#{content_type}"
end

#to_sObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/drupal/cck/builder.rb', line 54

def to_s
  "
    class #{content_type.camel_case}
      #{Drupal.common}
      storage_names[:drupal] = '#{table}'
      property :nid, Integer
      property :vid, Integer, :key => true
      belongs_to :node,
        :child_key => [:nid]
      #{columns.map{|c| c.to_s}.join "\n"}
      def self.content_type; :#{content_type}; end
      def content_type; :#{content_type}; end
      
      extend CCK::FieldMethods
      include CCK::Builder::InstanceMethods
    end
  "
end

#valid?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'lib/drupal/cck/builder.rb', line 73

def valid?
  columns
  true
rescue MysqlError
  false
end