Class: TinyUtil::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Config

config*

[
  {
    :key => :name, :value => 1, :desc => 'Hello World'
  },
  {
    :key => :age, :value => 2, :desc => 'Good'
  },
  {
    :desc => '地址',
    :group => [

    ]
  }
]


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tiny_util/config.rb', line 22

def initialize *args
  @config_values_map = {}
  @config_keys_map   = {}
  @select_options = impl_collect_select_options *args
  @keys_select_options = impl_collect_keys_select_options *args
  @default_item = nil

  impl_collect_item args

  @pure_values = @config_values_map.keys.freeze
  @pure_keys   = @config_keys_map.keys.freeze

  @config_values_map.freeze
  @config_keys_map.freeze
  @select_options.freeze
  @default_item.freeze

  self.freeze
end

Instance Attribute Details

#config_keys_mapObject (readonly)

Returns the value of attribute config_keys_map.



4
5
6
# File 'lib/tiny_util/config.rb', line 4

def config_keys_map
  @config_keys_map
end

#config_values_mapObject (readonly)

Returns the value of attribute config_values_map.



4
5
6
# File 'lib/tiny_util/config.rb', line 4

def config_values_map
  @config_values_map
end

#default_itemObject (readonly)

Returns the value of attribute default_item.



4
5
6
# File 'lib/tiny_util/config.rb', line 4

def default_item
  @default_item
end

#keys_select_optionsObject (readonly)

Returns the value of attribute keys_select_options.



4
5
6
# File 'lib/tiny_util/config.rb', line 4

def keys_select_options
  @keys_select_options
end

#pure_keysObject (readonly)

Returns the value of attribute pure_keys.



4
5
6
# File 'lib/tiny_util/config.rb', line 4

def pure_keys
  @pure_keys
end

#pure_valuesObject (readonly)

Returns the value of attribute pure_values.



4
5
6
# File 'lib/tiny_util/config.rb', line 4

def pure_values
  @pure_values
end

#select_optionsObject (readonly)

Returns the value of attribute select_options.



4
5
6
# File 'lib/tiny_util/config.rb', line 4

def select_options
  @select_options
end

Instance Method Details

#find_by_key(key, default = true) ⇒ Object



42
43
44
# File 'lib/tiny_util/config.rb', line 42

def find_by_key(key, default=true)
  @config_keys_map[key] || ((default && key != 'default') ? find_by_key('default', false) : nil)
end

#find_by_value(value, default = true) ⇒ Object



46
47
48
# File 'lib/tiny_util/config.rb', line 46

def find_by_value(value, default=true)
  @config_values_map[value] || (default ? find_by_key('default', false) : nil)
end

#to_keys_select_optionsObject



54
55
56
# File 'lib/tiny_util/config.rb', line 54

def to_keys_select_options
  @keys_select_options.dup
end

#to_select_optionsObject



50
51
52
# File 'lib/tiny_util/config.rb', line 50

def to_select_options
  @select_options.dup
end