Class: RailsBase::Configuration::User
- Defined in:
- lib/rails_base/configuration/user.rb
Constant Summary collapse
- USER_DEFINED_KEY =
'User Defined Zone'
- USER_DEFINED_ZONE =
{ USER_DEFINED_KEY => ->(user) { user.last_known_timezone } }
- ACTIVE_SUPPORT_MAPPING =
ActiveSupport::TimeZone::MAPPING.map do |key, value| [key, ->(*) { value }] end.to_h
- DEFAULT_TIMEZONES =
{ '' => ->(*) { ActiveSupport::TimeZone::MAPPING['UTC'] }, nil => ->(*) { ActiveSupport::TimeZone::MAPPING['UTC'] }, }
- ACCEPTED_TIMEZONES =
DEFAULT_TIMEZONES.merge(ACTIVE_SUPPORT_MAPPING).merge(USER_DEFINED_ZONE)
- DEFAULT_VALUES =
{ timezone: { type: :values, default: USER_DEFINED_KEY, description: 'The timezone to display to user.', on_assignment: ->(val, instance) { instance._timezone_convenience }, expect_values: ACCEPTED_TIMEZONES.keys, }, }
Constants inherited from Base
Instance Method Summary collapse
Methods inherited from Base
_allow_write_block?, _unset_allow_write!, #assign_default_values!, #dig, #initialize, #override_methods!, #validate!
Constructor Details
This class inherits a constructor from RailsBase::Configuration::Base
Instance Method Details
#_timezone_convenience ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rails_base/configuration/user.rb', line 31 def _timezone_convenience value = ACCEPTED_TIMEZONES[timezone] self.class.define_method('user_timezone') do |user| value.call(user) || ActiveSupport::TimeZone::MAPPING['UTC'] end self.class.define_method('tz_user_defined?') do timezone == USER_DEFINED_KEY end end |