Skip to content

Instantly share code, notes, and snippets.

@kannan4k
Created August 8, 2015 10:14
Show Gist options
  • Save kannan4k/e03ff11a56cea78453f8 to your computer and use it in GitHub Desktop.
Save kannan4k/e03ff11a56cea78453f8 to your computer and use it in GitHub Desktop.
require 'date'
class TSheets::Repository
attr_accessor :bridge, :cache
@@allowed_classes_for_spec = {
boolean: [ ::TrueClass, ::FalseClass ],
integer: [ ::Fixnum ],
string: [ ::String, ::Symbol ],
date: [ ::Date, ::DateTime ],
datetime: [ ::DateTime ]
}
def initialize(bridge, cache)
raise ArgumentError, "Expected initialized instance of TSheets::Bridge when initializing the repository" if !bridge.is_a?(TSheets::Bridge)
raise ArgumentError, "Expected initialized instance of TSheets::SupplementalCache when initializing the repository" if !cache.is_a?(TSheets::SupplementalCache)
self.bridge = bridge
self.cache = cache
end
def where(options)
with_action :list do
TSheets::Results.new url, self.validated_options(options), self.model, self.bridge, self.cache, self.is_singleton
end
end
class << self
def url address
define_method :url do
address
end
end
def model klass, options = {}
define_method :model do
klass
end
define_method :is_singleton do
options.fetch(:singleton, false)
end
end
def actions *list
define_method :actions do
list
end
end
def filter fname, type
@@filters ||= {}
@@filters[fname] = type
end
def inherited(child)
@@_descendants ||= []
@@_descendants.push child
end
def classes
@@_descendants
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment