Class: IfreeSms::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/ifree_sms/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(other = {}) ⇒ Config

Returns a new instance of Config.



30
31
32
33
34
35
36
37
38
39
# File 'lib/ifree_sms/config.rb', line 30

def initialize(other={})
  merge!(other)
  self[:routes] ||= "/ifree/sms"
  self[:secret_key] ||= "some_very_secret_key_given_ifree"
  self[:service_number] ||= "some_service_number"
  self[:project_name] ||= "project_name"
  self[:login] ||= "demo"
  self[:password] ||= "demo"
  self[:debug] ||= false
end

Class Method Details

.hash_accessor(*names) ⇒ Object

Creates an accessor that simply sets and reads a key in the hash:

class Config < Hash

hash_accessor :routes, :secret_key, :service_number, :project_name

end

config = Config.new config.routes = ‘/posts/message’ config #=> ‘/posts/message’



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ifree_sms/config.rb', line 14

def self.hash_accessor(*names) #:nodoc:
  names.each do |name|
    class_eval <<-METHOD, __FILE__, __LINE__ + 1
      def #{name}
        self[:#{name}]
      end

      def #{name}=(value)
        self[:#{name}] = value
      end
    METHOD
  end
end

Instance Method Details

#urlObject



41
42
43
# File 'lib/ifree_sms/config.rb', line 41

def url
  "http://srv1.com.ua/#{self[:project_name]}/second.php"
end