Module: Norton::Helper::ClassMethods
- Defined in:
- lib/norton/helper.rb
Instance Attribute Summary collapse
-
#norton_values ⇒ Object
readonly
Returns the value of attribute norton_values.
Instance Method Summary collapse
-
#norton_value_defined?(name) ⇒ Boolean
当前类是否定义了某个 Norton Value.
-
#norton_value_redis_pool(name) ⇒ ConnectionPool
返回当前类定义的某个 Norton Value 的 redis instance.
-
#norton_value_type(name) ⇒ Symbol
返回当前类定义的某个 Norton Value 的类型.
-
#register_norton_value(name, norton_type, options = {}) ⇒ void
当定义一个 Norton Value 的时候,将这个 Norton Value 记录在 Class Variable ‘@norton_values` 中.
Instance Attribute Details
#norton_values ⇒ Object (readonly)
Returns the value of attribute norton_values.
10 11 12 |
# File 'lib/norton/helper.rb', line 10 def norton_values @norton_values end |
Instance Method Details
#norton_value_defined?(name) ⇒ Boolean
当前类是否定义了某个 Norton Value
33 34 35 |
# File 'lib/norton/helper.rb', line 33 def norton_value_defined?(name) norton_values.has_key?(name.to_sym) end |
#norton_value_redis_pool(name) ⇒ ConnectionPool
返回当前类定义的某个 Norton Value 的 redis instance
55 56 57 58 |
# File 'lib/norton/helper.rb', line 55 def norton_value_redis_pool(name) pool_name = norton_values.dig(name.to_sym, :redis) || :default Norton.pools[pool_name] end |
#norton_value_type(name) ⇒ Symbol
返回当前类定义的某个 Norton Value 的类型
44 45 46 |
# File 'lib/norton/helper.rb', line 44 def norton_value_type(name) norton_values.dig(name.to_sym, :type) end |
#register_norton_value(name, norton_type, options = {}) ⇒ void
This method returns an undefined value.
当定义一个 Norton Value 的时候,将这个 Norton Value 记录在 Class Variable ‘@norton_values` 中
18 19 20 21 22 23 24 |
# File 'lib/norton/helper.rb', line 18 def register_norton_value(name, norton_type, = {}) if !Norton::SUPPORTED_TYPES.include?(norton_type.to_sym) raise Norton::InvalidType.new("Norton Type: #{norton_type} invalid!") end @norton_values[name.to_sym] = .symbolize_keys.merge(:type => norton_type.to_sym) end |