Sha256: 4f5b9c86b8dc58e3884212ae2001a0df7ffbfe672c7620dbea24ec1d35c71833

Contents?: true

Size: 1.28 KB

Versions: 20

Compression:

Stored size: 1.28 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)
          user['tags'].each do |tag|
            return tag[context_variable_key[USER_VALUE_TAG_PREFIX.length..]] if tag.key?(context_variable_key[USER_VALUE_TAG_PREFIX.length..])
          end
        end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
forest_liana-9.4.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.16 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.15 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.14 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.13 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.12 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.11 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.10 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.9 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.8 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.7 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.6 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.3 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.2 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.1 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.3.0 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.2.3 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.2.2 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.2.1 app/services/forest_liana/utils/context_variables.rb
forest_liana-9.2.0 app/services/forest_liana/utils/context_variables.rb