Module: Norton::Helper::ClassMethods

Defined in:
lib/norton/helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#norton_valuesObject (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

Parameters:

  • name (String/Symbol)

Returns:

  • (Boolean)


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

Parameters:

  • name (String)

Returns:

  • (ConnectionPool)


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 的类型

Parameters:

  • name (String)

Returns:

  • (Symbol)


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, options = {})
  if !Norton::SUPPORTED_TYPES.include?(norton_type.to_sym)
    raise Norton::InvalidType.new("Norton Type: #{norton_type} invalid!")
  end

  @norton_values[name.to_sym] = options.symbolize_keys.merge(:type => norton_type.to_sym)
end