Class: Bizside::Config

Inherits:
Object
  • Object
show all
Includes:
Bizside::Configurations::Mail, Bizside::Configurations::Prefix, Bizside::Configurations::Storage
Defined in:
lib/bizside/config.rb

Instance Method Summary collapse

Methods included from Bizside::Configurations::Storage

#storage

Methods included from Bizside::Configurations::Prefix

#prefix

Methods included from Bizside::Configurations::Mail

#default_url_options, #mail, #smtp_settings

Constructor Details

#initialize(hash = {}) ⇒ Config

Returns a new instance of Config.



11
12
13
# File 'lib/bizside/config.rb', line 11

def initialize(hash = {})
  @hash = hash || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bizside/config.rb', line 52

def method_missing(name, *args)
  ret = self[name]

  if ret.is_a?(Hash) || ret.is_a?(::Bizside::Config)
    unless args[0].nil?
      ret = self[name] = args[0]
    end
  end

  ret
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  key = key.to_s
  return (@hash[key[0..-2]] ? true : false) if key.end_with?('?')

  ret = @hash[key]
  if ret.nil?
    ret = self.class.new
  elsif ret.is_a?(Hash)
    ret = self.class.new(ret)
  end

  ret
end

#[]=(key, value) ⇒ Object



29
30
31
32
# File 'lib/bizside/config.rb', line 29

def []=(key, value)
  value = self.class.new(value) if value.is_a?(Hash)
  @hash[key.to_s] = value
end

#empty?Boolean

Hash継承時代での互換維持のために実装

Returns:

  • (Boolean)


39
40
41
# File 'lib/bizside/config.rb', line 39

def empty?
  @hash.empty?
end

#to_hObject



34
35
36
# File 'lib/bizside/config.rb', line 34

def to_h
  @hash.dup
end

#to_hashObject

オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれるメソッド Hash継承時代での互換維持のために実装。 なお、Hashの継承時代でも @hash を活用していたので、空ハッシュを返す



47
48
49
50
# File 'lib/bizside/config.rb', line 47

def to_hash
  warn "DEPRECATION WARNING: #{__method__} is deprecated and will be removed."
  {}
end