Sha256: 06e0924c8f741db8dd2930520d5886ce2dc407a02bcc4ae3ae03279df30863eb

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

class Eco::API::UseCases::DefaultCases::SetDefaultTagCase < Eco::API::Common::Loaders::UseCase
  name "set-default-tag"
  type :transform

  # take the deepest tag (the one that is further down in the tree)
  # different options (several nodes at the same depth):
  # => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
  # => if there's no common node between them, take the `first` (unless they are at top level of the tree)
  def main(people, session, options, usecase)
    tagtree_present!(session)
    users    = users_present!(people, session)
    update   = session.new_job("main", "update", :update, usecase, :account)

    users.each do |person|
      micro.refresh_default_tag(nil, person, options)
      update.add(person)
    end
  end

  private

  def tagtree_present!(session)
    if !session.tagtree
      msg = "There is no tagtree definition in the configuration files\n" +
            "For this usecase to work out you need to define it."
      session.logger.fatal(msg)
      raise msg
    end
  end

  def users_present!(people, session)
    people.users.tap do |users|
      unless users.length > 0
        session.logger.info(msg = "There are no people with account... aborting script")
        raise msg
      end
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
eco-helpers-2.5.10 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.9 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.8 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.7 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.6 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb