Class: SlackBot::View

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

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.



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

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#contextObject (readonly)

Returns the value of attribute context.



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.



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

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#text_modalObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/slack_bot/view.rb', line 25

def text_modal
  {
    title: {
      type: "plain_text",
      text: context[:title]
    },
    blocks: [
      {type: "section", text: {type: "mrkdwn", text: context[:text]}}
    ]
  }
end