<commit_before># this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/user'

module Import
  module Zendesk
    class User
      module Role
        extend Import::Helper

        # rubocop:disable Style/ModuleFunction
        extend self

        def for(user)
          map(user, group_method( user.role.name ))
        end

        def map(user, role)
          send(role.to_sym, user)
        rescue NoMethodError => e
          log "Unknown mapping for role '#{user.role.name}' and user with id '#{user.id}'"
          []
        end

        private

        def end_user(_user)
          [role_customer]
        end

        def agent(user)
          return [ role_agent ] if user.restricted_agent
          admin(user)
        end

        def admin(_user)
          [role_admin, role_agent]
        end

        def group_method(role)
          role.tr('-', '_')
        end

        def role_admin
          return @role_admin if @role_admin
          @role_admin = ::Role.lookup(name: 'Admin')
        end

        def role_agent
          return @role_agent if @role_agent
          @role_agent = ::Role.lookup(name: 'Agent')
        end

        def role_customer
          return @role_customer if @role_customer
          @role_customer = ::Role.lookup(name: 'Customer')
        end
      end
    end
  end
end<commit_msg>Improved code layout.<commit_after># this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/user'

module Import
  module Zendesk
    class User
      module Role
        extend Import::Helper

        # rubocop:disable Style/ModuleFunction
        extend self

        def for(user)
          map(user, group_method( user.role.name ))
        end

        def map(user, role)
          send(role.to_sym, user)
        rescue NoMethodError => e
          log "Unknown mapping for role '#{user.role.name}' and user with id '#{user.id}'"
          []
        end

        private

        def end_user(_user)
          [role_customer]
        end

        def agent(user)
          return [ role_agent ] if user.restricted_agent
          admin(user)
        end

        def admin(_user)
          [role_admin, role_agent]
        end

        def group_method(role)
          role.tr('-', '_')
        end

        def role_admin
          @role_admin ||= lookup('Admin')
        end

        def role_agent
          @role_agent ||= lookup('Agent')
        end

        def role_customer
          @role_customer ||= lookup('Customer')
        end

        def lookup(role_name)
          ::Role.lookup(name: role_name)
        end

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08268824771287825, 'fraction_numerical': 0.0, 'mean_word_length': 1.7982283464566928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6488608', 'n_tokens_mistral': 817, 'n_tokens_neox': 783, 'n_words': 225}