Module: Aliyun::Log::Record::Persistence::ClassMethods
- Defined in:
- lib/aliyun/log/record/persistence.rb
Instance Method Summary collapse
- #auto_load_schema ⇒ Object
- #create(data, opts = {}) ⇒ Object
- #create_logstore(options = {}) ⇒ Object
- #has_index? ⇒ Boolean
- #logstore_name ⇒ Object
- #logstore_name=(value) ⇒ Object
- #project_name ⇒ Object
- #sync_index ⇒ Object
Instance Method Details
#auto_load_schema ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/aliyun/log/record/persistence.rb', line 42 def auto_load_schema return if _schema_load create_logstore sync_index self._schema_load = true end |
#create(data, opts = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/aliyun/log/record/persistence.rb', line 57 def create(data, opts = {}) auto_load_schema if data.is_a?(Array) logs = data.map do |log_attr| new(log_attr).save_array end res = Log.record_connection.put_log(project_name, logstore_name, logs, opts) res.code == 200 else new(data).save end end |
#create_logstore(options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/aliyun/log/record/persistence.rb', line 31 def create_logstore( = {}) Log.record_connection.get_logstore(project_name, logstore_name) rescue ServerError => e Log.record_connection.create_logstore(project_name, logstore_name, ) end |
#has_index? ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/aliyun/log/record/persistence.rb', line 50 def has_index? Log.record_connection.get_index(project_name, logstore_name) true rescue ServerError false end |
#logstore_name ⇒ Object
10 11 12 13 |
# File 'lib/aliyun/log/record/persistence.rb', line 10 def logstore_name @logstore_name ||= [:name] || base_class.name.split('::').last.underscore.pluralize end |
#logstore_name=(value) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/aliyun/log/record/persistence.rb', line 15 def logstore_name=(value) if defined?(@logstore_name) return if value == @logstore_name end @logstore_name = value end |
#project_name ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/aliyun/log/record/persistence.rb', line 23 def project_name unless @project_name @project_name = [:project] || Config.project raise ProjectNameError, "project can't be empty" if @project_name.blank? end @project_name end |
#sync_index ⇒ Object
37 38 39 40 |
# File 'lib/aliyun/log/record/persistence.rb', line 37 def sync_index return if field_indices.blank? has_index? ? update_index : create_index end |