Skip to content

Instantly share code, notes, and snippets.

@calebhearth
Last active August 26, 2016 18:15
Show Gist options
  • Save calebhearth/fcdc769068e3e8882755352cd60a61da to your computer and use it in GitHub Desktop.
Save calebhearth/fcdc769068e3e8882755352cd60a61da to your computer and use it in GitHub Desktop.
class EmptyQueue
def initialize(company)
@company = company
end
def reasons
[
{
no_accounts: -> { company.accounts.none? },
no_approved_content: -> { company.approved_contents.none? },
},
{
no_contents_with_accounts: -> { company.contents_with_accounts.none? },
},
{
no_categories: -> { company.categories.none? },
no_timeslots: -> { company.schedules.none? },
},
{
no_scheduled_content_accounts: -> { company.scheduled_content_accounts.none? },
no_scheduled_content_categories: -> { company.scheduled_content_categories.none? },
},
{
all_content_use_once_and_used: -> { company.used_all_use_once_content? },
},
].lazy.
map { |level_reasons| level_reasons.select { |k,v| v.call }.keys }.
detect(&:any?) || []
end
private
attr_reader :company
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment