module TimeJawnPrivateClassMethods
Defines private methods necessary for TimeJawn
to work.
Private Instance Methods
class_date_attributes_or_arguments()
click to toggle source
returns all of the date_time attributes for a class unless it is specified in the class.
# File lib/time_jawn/time_jawn_private_class_methods.rb, line 43 def class_date_attributes_or_arguments @time_jawn_date_time_attributes || datetime_attributes end
datetime_attributes()
click to toggle source
Locates all of an ActiveRecord class' DateTime Attributes and returns them as an array of symbols.
# File lib/time_jawn/time_jawn_private_class_methods.rb, line 9 def datetime_attributes name.constantize.columns.map do |column| next unless column.type == :datetime column.name.to_sym end.compact end
generate_to_local(attribute)
click to toggle source
generates an instance method called “local_#{attribute}” that calls the to_local instance method.
# File lib/time_jawn/time_jawn_private_class_methods.rb, line 24 def generate_to_local(attribute) define_method(:"local_#{attribute}") { to_local(send(attribute)) } end
generate_to_local_with_assignment(attribute)
click to toggle source
generates an instance method called “local_#{attribute}=” that calls either the add_zone or _change_zone instance methods depending on the class of the input.
# File lib/time_jawn/time_jawn_private_class_methods.rb, line 31 def generate_to_local_with_assignment(attribute) define_method(:"local_#{attribute}=") do |time_or_string_value| if time_or_string_value.is_a? String write_attribute(attribute, add_zone(time_or_string_value)) else write_attribute(attribute, change_zone(time_or_string_value)) end end end
set_instance_variables(options_hash)
click to toggle source
# File lib/time_jawn/time_jawn_private_class_methods.rb, line 17 def set_instance_variables(options_hash) @time_zone_attribute_name = options_hash.fetch(:named, :time_zone) @time_jawn_date_time_attributes = options_hash.fetch(:time_attributes, nil) end