Module: Aliyun::Log::Record::Field

Extended by:
ActiveSupport::Concern
Included in:
Aliyun::Log::Record
Defined in:
lib/aliyun/log/record/field.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

PERMITTED_KEY_TYPES =

Types allowed in indexes:

%i[
  text
  long
  double
  json
].freeze
DEFAULT_INDEX_TOKEN =
", '\";=()[]{}?@&<>/:\n\t\r".split('')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



112
113
114
# File 'lib/aliyun/log/record/field.rb', line 112

def attributes
  @attributes
end

Instance Method Details

#attribute_namesObject



94
95
96
# File 'lib/aliyun/log/record/field.rb', line 94

def attribute_names
  @attributes.keys
end

#evaluate_default_value(val) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/aliyun/log/record/field.rb', line 102

def evaluate_default_value(val)
  if val.respond_to?(:call)
    val.call
  elsif val.duplicable?
    val.dup
  else
    val
  end
end

#has_attribute?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/aliyun/log/record/field.rb', line 98

def has_attribute?(attr_name)
  @attributes.key?(attr_name.to_sym)
end

#read_attribute(name) ⇒ Object Also known as: []



120
121
122
# File 'lib/aliyun/log/record/field.rb', line 120

def read_attribute(name)
  attributes[name.to_sym]
end

#set_created_atObject



125
126
127
# File 'lib/aliyun/log/record/field.rb', line 125

def set_created_at
  self.created_at ||= DateTime.now.in_time_zone(Time.zone).iso8601 if timestamps_enabled?
end

#timestamps_enabled?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/aliyun/log/record/field.rb', line 129

def timestamps_enabled?
  self.class.options[:timestamps] || (self.class.options[:timestamps].nil? && Config.timestamps)
end

#write_attribute(name, value) ⇒ Object Also known as: []=



114
115
116
# File 'lib/aliyun/log/record/field.rb', line 114

def write_attribute(name, value)
  attributes[name.to_sym] = TypeCasting.cast_field(value, self.class.attributes[name.to_sym])
end