Class: SlackBot::View

Inherits:
Object
  • Object
show all
Includes:
Concerns::PagerKlass
Defined in:
lib/slack_bot/view.rb,
sig/slack_bot.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::PagerKlass

included

Constructor Details

#initialize(current_user:, params:, args: nil, context: nil, config: nil) ⇒ View

Returns a new instance of View.

Parameters:

  • current_user: (Object)
  • params: (Hash[String, untyped])
  • args: (Args) (defaults to: nil)
  • context: (Hash[String, untyped]) (defaults to: nil)
  • config: (Config) (defaults to: nil)


10
11
12
13
14
15
16
17
# File 'lib/slack_bot/view.rb', line 10

def initialize(current_user:, params:, args: nil, context: nil, config: nil)
  @current_user = current_user
  @params = params
  @config = config || SlackBot::Config.current_instance

  @args = args
  @context = context.with_indifferent_access if context.is_a?(Hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



19
20
21
22
23
# File 'lib/slack_bot/view.rb', line 19

def method_missing(method_name, *args, &block)
  return @context[method_name.to_sym] if @context.is_a?(Hash) && @context.key?(method_name.to_sym)

  super
end

Instance Attribute Details

#argsArgs? (readonly)

Returns the value of attribute args.

Returns:



9
10
11
# File 'lib/slack_bot/view.rb', line 9

def args
  @args
end

#configConfig (readonly)

Returns the value of attribute config.

Returns:



9
10
11
# File 'lib/slack_bot/view.rb', line 9

def config
  @config
end

#contextHash[String, untyped]? (readonly)

Returns the value of attribute context.

Returns:

  • (Hash[String, untyped], nil)


9
10
11
# File 'lib/slack_bot/view.rb', line 9

def context
  @context
end

#current_userObject (readonly)

Returns the value of attribute current_user.

Returns:

  • (Object)


9
10
11
# File 'lib/slack_bot/view.rb', line 9

def current_user
  @current_user
end

#paramsHash[String, untyped] (readonly)

Returns the value of attribute params.

Returns:

  • (Hash[String, untyped])


9
10
11
# File 'lib/slack_bot/view.rb', line 9

def params
  @params
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/slack_bot/view.rb', line 25

def respond_to_missing?(method_name, include_private = false)
  (@context.is_a?(Hash) && @context.key?(method_name.to_sym)) || super
end

#text_modalHash[String, untyped]

Returns:

  • (Hash[String, untyped])


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/slack_bot/view.rb', line 29

def text_modal
  {
    title: {
      type: "plain_text",
      text: context&.dig(:title) || ""
    },
    blocks: [
      {type: "section", text: {type: "mrkdwn", text: context&.dig(:text) || ""}}
    ]
  }
end