Class: ActiveNotifier::Configurable::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/active_notifier/configurable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#const_nameObject

Alias const for ActiveNotifier



28
29
30
# File 'lib/active_notifier/configurable.rb', line 28

def const_name
  @const_name
end

Instance Method Details

#adapterObject

Message Adapter



46
47
48
# File 'lib/active_notifier/configurable.rb', line 46

def adapter
  @adapter || :dingtalk
end

#adapter=(adapter) ⇒ Object

Set message Adapter

Parameters:

  • adapter (#to_sym)

    (:dingtalk)



52
53
54
55
56
57
58
# File 'lib/active_notifier/configurable.rb', line 52

def adapter=(adapter)
  adapter = adapter.to_sym
  unless adapters_with_base_url.key?(adapter)
    raise ActiveNotifier::ConfigureError, "adapter only support: #{adapters_with_base_url.keys.join(', ')}"
  end
  @adapter = adapter
end

#adapters_with_base_urlObject

The adapters and its base url



103
104
105
106
107
# File 'lib/active_notifier/configurable.rb', line 103

def adapters_with_base_url
  @adapters_with_base_url ||= {
    dingtalk: "https://oapi.dingtalk.com/robot/send?access_token="
  }
end

#channel_tokensObject

The tokens of channel



61
62
63
# File 'lib/active_notifier/configurable.rb', line 61

def channel_tokens
  @channel_tokens || {}
end

#channel_tokens=(channel_tokens) ⇒ Object

Set the tokens of channel

Examples:

ActiveNotifier.config.channel_tokens = {
  default: "xxx",
  order: "xxx"
}

Parameters:

  • channel_tokens (#to_h)

    ({})



72
73
74
75
# File 'lib/active_notifier/configurable.rb', line 72

def channel_tokens=(channel_tokens)
  channel_tokens = channel_tokens.to_h.symbolize_keys
  @channel_tokens = channel_tokens
end

#priority_typeObject

The priority type for message, if notifier execute without type option and there are multiple valid types, then ActiveNotifier will use the template with this type first



92
93
94
# File 'lib/active_notifier/configurable.rb', line 92

def priority_type
  @priority_type || :markdown
end

#priority_type=(priority_type) ⇒ Object

Set the priority type

Parameters:

  • priority_type (#to_sym)

    (:markdown)



98
99
100
# File 'lib/active_notifier/configurable.rb', line 98

def priority_type=(priority_type)
  @priority_type = priority_type.to_sym
end

#template_homeObject

The template home directory



78
79
80
# File 'lib/active_notifier/configurable.rb', line 78

def template_home
  @template_home || "#{File.expand_path(__dir__)}/templates"
end

#template_home=(template_home) ⇒ Object

Set the template home directory

Parameters:

  • template_home (#to_s)

    (lib/active_notifier/templates)

Raises:



84
85
86
87
88
# File 'lib/active_notifier/configurable.rb', line 84

def template_home=(template_home)
  template_home = template_home.to_s
  raise ActiveNotifier::ConfigureError, "template_home value can't be blank" if template_home.empty?
  @template_home = template_home
end