Skip to content

Instantly share code, notes, and snippets.

@davidcelis
Created March 11, 2014 18:18
Show Gist options
  • Save davidcelis/9491797 to your computer and use it in GitHub Desktop.
Save davidcelis/9491797 to your computer and use it in GitHub Desktop.
require 'active_support/core_ext/time'
class BusinessHoursFeature
# This feature is only available between the hours of 10am and 4pm
def enabled?
Time.use_zone('Pacific Time (US & Canada)') do
now = Time.zone.now
am, pm = Time.zone.parse('10:00'), Time.zone.parse('16:00')
weekday = !(now.saturday? || now.sunday?)
now.between?(am, pm) && weekday
end
end
end
module Features
class NewRelicSingleSignOn < BusinessHoursFeature; end
end
Features::NewRelicSingleSignOn.new.enabled?
@dwayne
Copy link

dwayne commented Mar 24, 2014

Nice! Any reason why you guys chose a class over a module?

module BusinessHoursFeature
  def enabled?
    # ...
  end
end

module Features
  class NewRelicSingleSignOn
    include BusinessHoursFeature
  end
end

@davidcelis
Copy link
Author

No particular reason; my example was just a basic one. Module inclusion would also work really well if you want to combine feature aspects with each other. Though ordering may become tricky!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment