Class: Binda::Component

Inherits:
ApplicationRecord show all
Extended by:
FriendlyId
Includes:
AASM, FieldableAssociations
Defined in:
app/models/binda/component.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FieldableAssociations

#find_or_create_a_field_by, #generate_fields

Class Method Details

.remove_orphansObject



65
66
67
68
69
70
71
72
73
# File 'app/models/binda/component.rb', line 65

def self.remove_orphans
	Component
		.includes(:structure)
		.where(binda_structures: {id: nil})
		.each do |c|
			c.destroy!
			puts "Binda::Component with id ##{c.id} successfully destroyed"
		end
end

.sort_limitObject

The limit above which componets cannot be sorted anymore



51
52
53
# File 'app/models/binda/component.rb', line 51

def self.sort_limit
	1000
end

Instance Method Details

#create_field_instancesObject

Create field instances for the current component



56
57
58
59
60
61
62
63
# File 'app/models/binda/component.rb', line 56

def create_field_instances
  	instance_field_settings = FieldSetting
  		.includes(field_group: [ :structure ])
  		.where(binda_structures: { id: self.structure.id })
  	instance_field_settings.each do |field_setting|
  		field_setting.create_field_instance_for(self)
  	end
end

#should_generate_new_friendly_id?Boolean

Friendly id preference on slug generation

Method inherited from friendly id



46
47
48
# File 'app/models/binda/component.rb', line 46

def should_generate_new_friendly_id?
	slug.blank?
end