Sha256: 2b32647aa0dd592bf80b650fd7382a9c2c2c22d96e5a86546ca1144281cf3388

Contents?: true

Size: 1.72 KB

Versions: 26

Compression:

Stored size: 1.72 KB

Contents

module Eco
  module API
    class UseCases
      class DefaultCases
        class SetDefaultTagCase < DefaultCase
          # 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, usecase|
              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

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

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

              update   = session.job_group("main").new("update", usecase: usecase, 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.filter_tags)
                update.add(person)
              end

            end
          end

        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
eco-helpers-1.3.15 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.14 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.13 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.12 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.11 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.10 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.9 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.8 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.7 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.6 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.5 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.4 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.3 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.3.1 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.2.2 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.2.1 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.1.8 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.1.7 lib/eco/api/usecases/default_cases/set_default_tag_case.rb
eco-helpers-1.1.6 lib/eco/api/usecases/default_cases/set_default_tag_case.rb