Module: Contentful::DatabaseImporter::ResourceClassMethods

Defined in:
lib/contentful/database_importer/resource_class_methods.rb

Overview

Class Methods for Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#id_generatorObject

Returns the value of attribute id_generator.



6
7
8
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 6

def id_generator
  @id_generator
end

Instance Method Details

#allObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 71

def all
  entries = []
  rows = if query.nil?
           table.all
         else
           table.where(query).all
         end

  rows.each_with_index do |row, index|
    entries << new(row, index)
  end

  entries
end

#content_type_idObject



16
17
18
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 16

def content_type_id
  @content_type_id || Support.snake_case(name)
end

#content_type_id=(ct_id) ⇒ Object



20
21
22
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 20

def content_type_id=(ct_id)
  @content_type_id = ct_id
end

#content_type_nameObject



24
25
26
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 24

def content_type_name
  (@content_type_name || name)
end

#content_type_name=(name) ⇒ Object



28
29
30
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 28

def content_type_name=(name)
  @content_type_name = name
end

#default_generator_optionsObject



40
41
42
43
44
45
46
47
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 40

def default_generator_options
  {
    table_name: table_name,
    content_type_id: content_type_id,
    class_name: name,
    template: '{{content_type_id}}_{{index}}'
  }
end

#display_fieldObject



55
56
57
58
59
60
61
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 55

def display_field
  default_display_field = fields.reject { |f| f[:exclude_from_output] }.find do |f|
    f[:type] == :string || f[:type] == :symbol
  end || {}

  @display_field || default_display_field[:maps_to]
end

#display_field=(field_name) ⇒ Object



63
64
65
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 63

def display_field=(field_name)
  @display_field = field_name
end

#id(id_generator_class, options = {}) ⇒ Object



49
50
51
52
53
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 49

def id(id_generator_class, options = {})
  @id_generator = id_generator_class.new(
    default_generator_options.merge(options)
  )
end

#queryObject



32
33
34
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 32

def query
  @query
end

#query=(query) ⇒ Object



36
37
38
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 36

def query=(query)
  @query = query
end

#tableObject



67
68
69
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 67

def table
  Contentful::DatabaseImporter.database[table_name]
end

#table_nameObject



8
9
10
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 8

def table_name
  (@table_name || Support.snake_case(name)).to_sym
end

#table_name=(name) ⇒ Object



12
13
14
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 12

def table_name=(name)
  @table_name = name
end