Skip to content

Instantly share code, notes, and snippets.

@tusharmath
Last active August 29, 2015 13:58
Show Gist options
  • Save tusharmath/9931602 to your computer and use it in GitHub Desktop.
Save tusharmath/9931602 to your computer and use it in GitHub Desktop.
A solution to resolve awfully customized event scheduling
class IEvent
constructor: ->
@_rules = []
set_description: (@description) ->
is_it_on: (date) ->
sorted_rules = @_rules
for rule in sorted_rules
if rule.execute date is yes
true
false
add_schedule_rule: (IRule) -> #Adds a schedule
reorder_rule_collection: (FinalOrderMap) ->
serialize: -> #creates an ob with evnt description and serialized rules.
class IRuleInitParams
class IRuleExecuteParams
class IRule
constructor: (IRuleInitParams) ->
clone: () -> #returns a clone of the rule
execute: (IRuleExecuteParams) ->
serialize: -> {rule_name, rule_executeparams}
class Daily extends IRule
#Contains all the rules
class RuleContainer
constructor: ->
@_rule_collection = []
register_container: (name, schedule_rule) ->
@_rule_collection.push {name, schedule_rule}
fetch_container: (name) -> @_rule_collection.where item -> item.name is name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment