Class: Locomotive::Wagon::ContentTypeDecorator

Inherits:
SimpleDelegator
  • Object
show all
Includes:
ToHashConcern
Defined in:
lib/locomotive/wagon/decorators/content_type_decorator.rb

Instance Method Summary collapse

Methods included from ToHashConcern

#prepare_value_for_hash, #to_hash

Constructor Details

#initialize(entity, existing_fields = []) ⇒ ContentTypeDecorator

Returns a new instance of ContentTypeDecorator.



8
9
10
11
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 8

def initialize(entity, existing_fields = [])
  @existing_fields = existing_fields
  super(entity)
end

Instance Method Details

#__attributes__Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 13

def __attributes__
  %i(name slug description label_field_name tree_parent_field_name fields
    order_by order_direction group_by
    public_submission_enabled
    public_submission_accounts
    public_submission_title_template
    public_submission_email_attachments
    recaptcha_required entry_template display_settings filter_fields 
    import_enabled)
end

#descriptionObject



39
40
41
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 39

def description
  self[:description]
end

#display_settingsObject



71
72
73
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 71

def display_settings
  self[:display_settings]
end

#entry_templateObject



67
68
69
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 67

def entry_template
  self[:entry_template]
end

#fieldsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 24

def fields
  return @fields if @fields

  @fields = __getobj__.fields.no_associations.map { |f| ContentTypeFieldDecorator.new(f, @existing_fields.include?(f.name)) }

  @existing_fields.each do |name|
    # the field exists remotely but does not exist locally, delete it
    if __getobj__.fields.by_name(name).nil?
      @fields.insert(0, { name: name, _destroy: true })
    end
  end

  @fields
end

#filter_fieldsObject



75
76
77
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 75

def filter_fields
  self[:filter_fields]
end

#group_byObject



47
48
49
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 47

def group_by
  self[:group_by]
end

#import_enabledObject



87
88
89
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 87

def import_enabled
  self[:import_enabled]
end

#order_byObject



43
44
45
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 43

def order_by
  self[:order_by]
end

#public_submission_accountsObject



55
56
57
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 55

def public_submission_accounts
  self[:public_submission_accounts]
end

#public_submission_email_attachmentsObject



63
64
65
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 63

def public_submission_email_attachments
  self[:public_submission_email_attachments]
end

#public_submission_enabledObject



51
52
53
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 51

def public_submission_enabled
  self[:public_submission_enabled]
end

#public_submission_title_templateObject



59
60
61
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 59

def public_submission_title_template
  self[:public_submission_title_template]
end

#recaptcha_requiredObject



83
84
85
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 83

def recaptcha_required
  self[:recaptcha_required]
end

#tree_parent_field_nameObject



79
80
81
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 79

def tree_parent_field_name
  self[:tree_parent_field_name]
end

#with_relationships?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/locomotive/wagon/decorators/content_type_decorator.rb', line 91

def with_relationships?
  __getobj__.fields.associations.count > 0
end