Skip to content

Commit

Permalink
DEV: Use plugin API to amend Post class (#57)
Browse files Browse the repository at this point in the history
This ensures that the patch is reloaded automatically during development, and should stop the random `NoMethodError (undefined method `group_timezones' for #<Post>` errors in development
  • Loading branch information
davidtaylorhq committed Aug 10, 2020
1 parent 519f522 commit 6f06bc8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions plugin.rb
Expand Up @@ -305,21 +305,19 @@ def valid_event
validator.validate_event
end

Post.class_eval do
def has_group_timezones?
custom_fields[DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD].present?
end
add_to_class(:post, :has_group_timezones?) do
custom_fields[DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD].present?
end

def group_timezones
custom_fields[DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD] || {}
end
add_to_class(:post, :group_timezones) do
custom_fields[DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD] || {}
end

def group_timezones=(val)
if val.present?
custom_fields[DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD] = val
else
custom_fields.delete(DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD)
end
add_to_class(:post, :group_timezones=) do |val|
if val.present?
custom_fields[DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD] = val
else
custom_fields.delete(DiscourseCalendar::GROUP_TIMEZONES_CUSTOM_FIELD)
end
end

Expand Down

0 comments on commit 6f06bc8

Please sign in to comment.