Sha256: bfe9e65b7d7142c663009a6dec457ca742d7241baf5bd9fb6e8e20d973f046ca

Contents?: true

Size: 1.27 KB

Versions: 27

Compression:

Stored size: 1.27 KB

Contents

module ForestLiana
  module Utils
    class ContextVariables
      attr_reader :team, :user, :request_context_variables

      USER_VALUE_PREFIX = 'currentUser.'.freeze

      USER_VALUE_TAG_PREFIX = 'currentUser.tags.'.freeze

      USER_VALUE_TEAM_PREFIX = 'currentUser.team.'.freeze

      def initialize(team, user, request_context_variables = nil)
        @team = team
        @user = user
        @request_context_variables = request_context_variables
      end

      def get_value(context_variable_key)
        return get_current_user_data(context_variable_key) if context_variable_key.start_with?(USER_VALUE_PREFIX)

        request_context_variables[context_variable_key] if request_context_variables
      end

      private

      def get_current_user_data(context_variable_key)
        if context_variable_key.start_with?(USER_VALUE_TEAM_PREFIX)
          return team[context_variable_key[USER_VALUE_TEAM_PREFIX.length..]]
        end

        if context_variable_key.start_with?(USER_VALUE_TAG_PREFIX)
          tag_key = context_variable_key[USER_VALUE_TAG_PREFIX.length..]
          user['tags'].each do |tag|
            return tag['value'] if tag['key'] == tag_key
          end
        end

        user[context_variable_key[USER_VALUE_PREFIX.length..]]
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
forest_liana-9.11.1 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.11.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.10.6 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.10.5 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.10.4 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.10.3 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.10.2 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.10.1 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.10.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.9.1 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.9.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.8.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.7.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.6.4 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.6.3 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.6.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.5.7 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.5.6 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.5.5 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.5.4 app/services/forest_liana/utils/context_variables.rb