Class: Lazybird::LazybirdFacade
- Inherits:
-
Object
- Object
- Lazybird::LazybirdFacade
- Defined in:
- lib/lazybird/lazybird_facade.rb
Overview
TODO: split this file
Instance Attribute Summary collapse
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #add_task(task_name) ⇒ Object
- #config(params) ⇒ Object
- #current_tasks ⇒ Object
- #init ⇒ Object
-
#initialize ⇒ LazybirdFacade
constructor
A new instance of LazybirdFacade.
- #load_default_tasks ⇒ Object
- #rem_task(task_name) ⇒ Object
- #run_info ⇒ Object
- #run_tasks(params, &block) ⇒ Object
Constructor Details
#initialize ⇒ LazybirdFacade
Returns a new instance of LazybirdFacade.
14 15 16 17 |
# File 'lib/lazybird/lazybird_facade.rb', line 14 def initialize @current_tasks = Set.new @tasks = Lazybird::Config.tasks end |
Instance Attribute Details
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
12 13 14 |
# File 'lib/lazybird/lazybird_facade.rb', line 12 def tasks @tasks end |
Instance Method Details
#add_task(task_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lazybird/lazybird_facade.rb', line 19 def add_task(task_name) # TODO refactor this method found = Lazybird::Utils::Hash.find_by_key(@tasks, task_name) if found task = Object.const_get(found[task_name]['class']).new(command: task_name) begin Lazybird::Db.save_task!(task) rescue Sequel::UniqueConstraintViolation puts 'Task added already'.light_red end @current_tasks << task end end |
#config(params) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/lazybird/lazybird_facade.rb', line 50 def config(params) config = Lazybird::Utils::Hash.array_to_hash([:consumer_key, :consumer_secret, :access_token, :access_token_secret], params) Lazybird::Db.save_config! config end |
#current_tasks ⇒ Object
38 39 40 |
# File 'lib/lazybird/lazybird_facade.rb', line 38 def current_tasks @current_tasks.map { |t| t.command } end |
#init ⇒ Object
46 47 48 |
# File 'lib/lazybird/lazybird_facade.rb', line 46 def init Lazybird::Db.init end |
#load_default_tasks ⇒ Object
42 43 44 |
# File 'lib/lazybird/lazybird_facade.rb', line 42 def load_default_tasks @current_tasks.merge(Lazybird::Db.tasks) end |
#rem_task(task_name) ⇒ Object
33 34 35 36 |
# File 'lib/lazybird/lazybird_facade.rb', line 33 def rem_task(task_name) Lazybird::Db.rem_task!(task_name) @current_tasks.delete_if { |t| t.command == task_name } end |
#run_info ⇒ Object
68 69 70 |
# File 'lib/lazybird/lazybird_facade.rb', line 68 def run_info Lazybird::Tasks::TaskScheduler.job_info end |
#run_tasks(params, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/lazybird/lazybird_facade.rb', line 58 def run_tasks(params, &block) if params.first == 'now' run_random_task else Lazybird::Tasks::TaskScheduler.schedule(frequency: params.first) do run_random_task(&block) end end end |