Module: Timely::Extensions

Defined in:
lib/timely/rails/extensions.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_seasonalObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/timely/rails/extensions.rb', line 17

def acts_as_seasonal
  belongs_to :season, class_name: 'Timely::Season', optional: true
  accepts_nested_attributes_for :season
  validates_associated :season

  before_save do |object|
    next unless object.season

    object.boundary_start = object.season.boundary_start
    object.boundary_end   = object.season.boundary_end
  end
end

#weekdays_field(attribute, options = {}) ⇒ Object

Add a WeekDays attribute

By default it will use attribute_bit_array as db field, but this can be overridden by specifying :db_field => ‘somthing_else’



9
10
11
12
13
14
15
# File 'lib/timely/rails/extensions.rb', line 9

def weekdays_field(attribute, options = {})
  db_field = options[:db_field] || attribute.to_s + '_bit_array'
  composed_of(attribute,
              class_name: '::Timely::WeekDays',
              mapping: [[db_field, 'weekdays_int']],
              converter: proc { |field| ::Timely::WeekDays.new(field) })
end