Class: Smess::Config
- Inherits:
-
Object
- Object
- Smess::Config
- Defined in:
- lib/smess.rb
Instance Attribute Summary collapse
-
#configured_outputs ⇒ Object
Returns the value of attribute configured_outputs.
-
#default_output ⇒ Object
Returns the value of attribute default_output.
-
#default_sender_id ⇒ Object
Returns the value of attribute default_sender_id.
-
#nothing ⇒ Object
Returns the value of attribute nothing.
-
#output_by_country_code ⇒ Object
Returns the value of attribute output_by_country_code.
-
#output_types ⇒ Object
Returns the value of attribute output_types.
Instance Method Summary collapse
- #add_country_code(cc, output = default_output) ⇒ Object
- #country_codes ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #outputs ⇒ Object
- #register_output(options) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/smess.rb', line 53 def initialize @nothing = false @default_output = nil @default_sender_id = "Smess" @output_types = %i{auto card_board_fish clickatell global_mouth link_mobility smsglobal twilio twilio_whatsapp} @configured_outputs = {} @output_by_country_code = {} if ENV["RAILS_ENV"] == "test" @configured_outputs = {test: {type: :test, config: nil}} end register_output({ name: :auto, country_codes: [], type: :auto, config: {} }) end |
Instance Attribute Details
#configured_outputs ⇒ Object
Returns the value of attribute configured_outputs.
51 52 53 |
# File 'lib/smess.rb', line 51 def configured_outputs @configured_outputs end |
#default_output ⇒ Object
Returns the value of attribute default_output.
51 52 53 |
# File 'lib/smess.rb', line 51 def default_output @default_output end |
#default_sender_id ⇒ Object
Returns the value of attribute default_sender_id.
51 52 53 |
# File 'lib/smess.rb', line 51 def default_sender_id @default_sender_id end |
#nothing ⇒ Object
Returns the value of attribute nothing.
51 52 53 |
# File 'lib/smess.rb', line 51 def nothing @nothing end |
#output_by_country_code ⇒ Object
Returns the value of attribute output_by_country_code.
51 52 53 |
# File 'lib/smess.rb', line 51 def output_by_country_code @output_by_country_code end |
#output_types ⇒ Object
Returns the value of attribute output_types.
51 52 53 |
# File 'lib/smess.rb', line 51 def output_types @output_types end |
Instance Method Details
#add_country_code(cc, output = default_output) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/smess.rb', line 73 def add_country_code(cc, output=default_output) raise ArgumentError.new("Invalid country code") unless cc.to_i.to_s == cc.to_s raise ArgumentError.new("Unknown output specified") unless outputs.include? output.to_sym output_by_country_code[cc.to_s] = output.to_sym true end |
#country_codes ⇒ Object
99 100 101 |
# File 'lib/smess.rb', line 99 def country_codes output_by_country_code.keys end |
#outputs ⇒ Object
95 96 97 |
# File 'lib/smess.rb', line 95 def outputs configured_outputs.keys end |
#register_output(options) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/smess.rb', line 80 def register_output() name = .fetch(:name).to_sym type = .fetch(:type).to_sym countries = .fetch(:country_codes) config = .fetch(:config) raise ArgumentError.new("Duplicate output name") if outputs.include? name raise ArgumentError.new("Unknown output type specified") unless output_types.include? type configured_outputs[name] = {type: type, config: config} countries.each do |cc| add_country_code(cc, name) end end |