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.1.9 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.8 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.7 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.6 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.1.1 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.68 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.67 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.66 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.65 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.64 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.63 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.62 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.61 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.60 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.59 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-2.0.58 lib/eco/api/usecases/default_cases/set_default_tag_case.rb