Class: Saint::ClassApi::OptsPool
- Inherits:
-
Object
- Object
- Saint::ClassApi::OptsPool
- Defined in:
- lib/saint/api/class/opts.rb
Instance Attribute Summary (collapse)
-
- (Object) opts
readonly
Returns the value of attribute opts.
-
- (Object) pool
readonly
Returns the value of attribute pool.
Instance Method Summary (collapse)
- - (Object) [](opt)
- - (Object) []=(opt, val)
-
- (OptsPool) initialize(pool, table = nil, &proc)
constructor
A new instance of OptsPool.
-
- (Object) opt(name, *type_and_or_opts)
add new opt to OptsManager.
Constructor Details
- (OptsPool) initialize(pool, table = nil, &proc)
A new instance of OptsPool
8 9 10 11 12 13 |
# File 'lib/saint/api/class/opts.rb', line 8 def initialize pool, table = nil, &proc @pool = pool || Presto::Cache::Memory.new @pool = @pool.new(normalize_name(table)) if table @opts = {} self.instance_exec &proc end |
Instance Attribute Details
- (Object) opts (readonly)
Returns the value of attribute opts
6 7 8 |
# File 'lib/saint/api/class/opts.rb', line 6 def opts @opts end |
- (Object) pool (readonly)
Returns the value of attribute pool
6 7 8 |
# File 'lib/saint/api/class/opts.rb', line 6 def pool @pool end |
Instance Method Details
- (Object) [](opt)
38 39 40 41 |
# File 'lib/saint/api/class/opts.rb', line 38 def [] opt return unless item = @pool[opt] item['value'] || item['default_value'] end |
- (Object) []=(opt, val)
43 44 45 46 |
# File 'lib/saint/api/class/opts.rb', line 43 def []= opt, val return unless item = @pool[opt] @pool.update opt => item.update('value' => val) end |
- (Object) opt(name, *type_and_or_opts)
add new opt to OptsManager.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/saint/api/class/opts.rb', line 22 def opt name, *type_and_or_opts type, opts = :string, {} type_and_or_opts.each { |a| a.is_a?(Hash) ? opts.update(a) : type = a } name = normalize_name(name) opts['name'] = name opts['type'] = type.to_s opts['details'] = opts.delete(:details) opts['default_value'] = opts.delete(:default) if = opts.delete(:options) = Hash[.zip()] if .is_a?(Array) end opts['options'] = .is_a?(Hash) ? : {} @pool[name] = opts @opts[name] = opts end |