Module: Contentful::DatabaseImporter::ResourceClassMethods
- Defined in:
- lib/contentful/database_importer/resource_class_methods.rb
Overview
Class Methods for Resource
Instance Attribute Summary collapse
-
#id_generator ⇒ Object
Returns the value of attribute id_generator.
Instance Method Summary collapse
- #all ⇒ Object
- #content_type_id ⇒ Object
- #content_type_id=(ct_id) ⇒ Object
- #content_type_name ⇒ Object
- #content_type_name=(name) ⇒ Object
- #default_generator_options ⇒ Object
- #display_field ⇒ Object
- #display_field=(field_name) ⇒ Object
- #id(id_generator_class, options = {}) ⇒ Object
- #query ⇒ Object
- #query=(query) ⇒ Object
- #table ⇒ Object
- #table_name ⇒ Object
- #table_name=(name) ⇒ Object
Instance Attribute Details
#id_generator ⇒ Object
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
#all ⇒ Object
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_id ⇒ Object
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_name ⇒ Object
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_options ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 40 def { table_name: table_name, content_type_id: content_type_id, class_name: name, template: '{{content_type_id}}_{{index}}' } end |
#display_field ⇒ Object
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, = {}) @id_generator = id_generator_class.new( .merge() ) end |
#query ⇒ Object
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 |
#table ⇒ Object
67 68 69 |
# File 'lib/contentful/database_importer/resource_class_methods.rb', line 67 def table Contentful::DatabaseImporter.database[table_name] end |
#table_name ⇒ Object
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 |