Module: Binda::FieldableAssociationHelpers::FieldableDateHelpers

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

Instance Method Summary collapse

Instance Method Details

#get_date(field_slug) ⇒ boolean

Get the object related to that field setting

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (boolean)

Raises:

  • (ArgumentError)


23
24
25
26
27
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_date_helpers.rb', line 23

def get_date(field_slug)
	obj = self.dates.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any date associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	obj.date
end

#has_date(field_slug) ⇒ datetime, boolean

Check if the field has an attached date

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (datetime)

    The date

  • (boolean)

    Reutrn false if nothing is found

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_date_helpers.rb', line 9

def has_date(field_slug)
	obj = self.dates.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any date associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	if obj.present?
		return !obj.date.nil?
	else
		return false
	end
end