Sha256: 98f6a26a53944016f737dc378d4ff385f20c3f9adb892430f35dfba28dce73cd

Contents?: true

Size: 1.66 KB

Versions: 22

Compression:

Stored size: 1.66 KB

Contents

module Eco
  module API
    module UseCases
      class DefaultCases
        class SetDefaultTagCase < BaseCase
          # 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 process
            @cases.define("set-default-tag", type: :transform) do |people, session, options|
              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)
                exit
              end

              # IMPORTANT: this two lines ensure that only people to be updated is selected
              all_people = people
              people = people.account_present

              if people.length <= 0
                session.logger.info("There are no people with account... aborting script")
                exit
              end

              update   = session.job_group("main").new("update", type: :update, sets: :account)

              people.each_with_index  do |person, i|
                #next unless person.id == "5c527ba63f7690001243f5b2"
                person.account.default_tag = session.tagtree.default_tag(*person.account.filter_tags)
                update.add(person)
              end

            end
          end

        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
eco-helpers-0.8.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.8.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.8.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.8.1 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.7.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.7.1 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.17 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.16 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.15 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.13 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.12 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.11 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.9 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.8 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.7 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.6 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-0.6.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb