Module: Binda::FieldableAssociationHelpers::FieldableRepeaterHelpers

Included in:
Binda::FieldableAssociationHelpers
Defined in:
app/models/concerns/binda/fieldable_association_helpers/fieldable_repeater_helpers.rb

Instance Method Summary collapse

Instance Method Details

#get_repeater(field_slug) ⇒ Object



26
27
28
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_repeater_helpers.rb', line 26

def get_repeater(field_slug)
	get_repeaters(field_slug)
end

#get_repeaters(field_slug) ⇒ array

Get the all repeater instances sorted by position

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (array)

    An array of repeater items which have all sorts of fields attached

Raises:

  • (ArgumentError)


21
22
23
24
25
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_repeater_helpers.rb', line 21

def get_repeaters(field_slug)
	obj = self.repeaters.find_all{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any repeater associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	obj.sort_by(&:position)
end

#has_repeater(field_slug) ⇒ Object



13
14
15
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_repeater_helpers.rb', line 13

def has_repeater(field_slug)
	has_repeaters(field_slug)
end

#has_repeaters(field_slug) ⇒ boolean

Check if exists any repeater with that slug

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (boolean)

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_repeater_helpers.rb', line 8

def has_repeaters(field_slug)
	obj = self.repeaters.find_all{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any repeater associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	return obj.present?
end