lib/kamerling/repos.rb in kamerling-0.0.2 vs lib/kamerling/repos.rb in kamerling-0.0.3
- old
+ new
@@ -1,65 +1,72 @@
warn_off { require 'sequel' }
+require_relative 'client'
+require_relative 'project'
+require_relative 'registration'
+require_relative 'repo'
+require_relative 'task'
Sequel.extension :migration
-module Kamerling class Repos
- class << self
- attr_writer :repos
+module Kamerling
+ class Repos
+ class << self
+ attr_writer :repos
- def << object
- repos[object.class] << object
- self
- end
+ def <<(object)
+ repos[object.class] << object
+ self
+ end
- def [] klass
- repos[klass]
- end
+ def [](klass)
+ repos[klass]
+ end
- def clients
- repos[Client].all
- end
+ def clients
+ repos[Client].all
+ end
- def clients_for project
- repos[Registration].related_to(project).map(&:client)
- end
+ def clients_for(project)
+ repos[Registration].related_to(project).map(&:client)
+ end
- def db= db
- warn_off { Sequel::Migrator.run db, "#{__dir__}/migrations" }
- @repos = nil
- @db = db
- end
+ def db=(db)
+ warn_off { Sequel::Migrator.run db, "#{__dir__}/migrations" }
+ @repos = nil
+ @db = db
+ end
- def free_clients_for project
- clients_for(project).reject(&:busy)
- end
+ def free_clients_for(project)
+ clients_for(project).reject(&:busy)
+ end
- def next_task_for project
- repos[Task].related_to(project).reject(&:done).first
- end
+ def next_task_for(project)
+ repos[Task].related_to(project).reject(&:done).first
+ end
- def project project_uuid
- repos[Project][project_uuid]
- end
+ def project(project_uuid)
+ repos[Project][project_uuid]
+ end
- def projects
- repos[Project].all
- end
+ def projects
+ repos[Project].all
+ end
- def tasks_for project
- repos[Task].related_to project
- end
+ def tasks_for(project)
+ repos[Task].related_to(project)
+ end
- private
+ private
- def db
- @db ||= self.db = Sequel.sqlite
- end
+ def db
+ @db ||= self.db = Sequel.sqlite
+ end
- def repos
- @repos ||= Hash.new do |repos, klass|
- table = "#{klass.name.split('::').last.downcase}s".to_sym
- repos[klass] = Repo.new klass, warn_off { db[table] }
+ def repos
+ @repos ||= Hash.new do |repos, klass|
+ table = "#{klass.name.split('::').last.downcase}s".to_sym
+ repos[klass] = Repo.new(klass, warn_off { db[table] })
+ end
end
end
end
-end end
+end