Sha256: f6df9283a43f36262f573b4c484716a44882c500bf80fbad168c17f5f7907a0d

Contents?: true

Size: 1.34 KB

Versions: 109

Compression:

Stored size: 1.34 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)
    micro    = session.micro
    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

109 entries across 109 versions & 1 rubygems

Version Path
eco-helpers-2.5.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.5.1 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.9 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.8 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.7 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.6 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.4.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.3.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.3.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.2.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.2.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.2.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.2.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.2.1 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.12 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.11 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.10 lib/eco/api/usecases/default_cases/set_default_tag_case.rb