module EsExperiment::Actions::Create
Public Instance Methods
create(name, options = {})
click to toggle source
# File lib/es_experiment/actions/create.rb, line 5 def create(name, options = {}) client.index params(name, options) end
Private Instance Methods
doc(name, options)
click to toggle source
# File lib/es_experiment/actions/create.rb, line 22 def doc(name, options) doc = documents.get(name) update(doc, options[:fields]) unless options[:fields].nil? doc end
params(name, options)
click to toggle source
# File lib/es_experiment/actions/create.rb, line 11 def params(name, options) { index: config.index, type: options[:type] || '_doc', id: options[:id], body: doc(name, options), version: options[:version], version_type: options[:version_type], routing: options[:routing], refresh: true }.compact end
parse_key(full_key)
click to toggle source
rubocop:enable Security/Eval
# File lib/es_experiment/actions/create.rb, line 38 def parse_key(full_key) full_key .to_s .split('.') .map { |key| "['#{key}']" } .join end
parse_value(value)
click to toggle source
# File lib/es_experiment/actions/create.rb, line 46 def parse_value(value) return "'#{value}'" if value.is_a? String value end
update(doc, fields)
click to toggle source
rubocop:disable Security/Eval
# File lib/es_experiment/actions/create.rb, line 29 def update(doc, fields) fields.each do |full_key, value| eval <<-RUBY, binding, __FILE__, __LINE__ + 1 doc#{parse_key(full_key)} = #{parse_value(value)} RUBY end end