class Cauchy::IndexSchema
Attributes
index_alias[RW]
Public Class Methods
define(index_alias, &block)
click to toggle source
# File lib/cauchy/index_schema.rb, line 12 def define(index_alias, &block) index_alias = index_alias.to_s schemas[index_alias] = new(index_alias).tap { |s| s.define(&block) } end
load_schemas(paths)
click to toggle source
# File lib/cauchy/index_schema.rb, line 17 def load_schemas(paths) Dir[*Array(paths).map { |p| "#{p}/**/*.rb" }].each { |f| load f } end
new(index_alias)
click to toggle source
# File lib/cauchy/index_schema.rb, line 33 def initialize(index_alias) @index_alias = index_alias end
schemas()
click to toggle source
# File lib/cauchy/index_schema.rb, line 21 def schemas @@schemas end
schemas=(schemas)
click to toggle source
# File lib/cauchy/index_schema.rb, line 25 def schemas=(schemas) @@schemas = schemas end
Public Instance Methods
define(&block)
click to toggle source
# File lib/cauchy/index_schema.rb, line 37 def define(&block) instance_eval(&block) end
mapping_for(type)
click to toggle source
# File lib/cauchy/index_schema.rb, line 52 def mapping_for(type) return unless mappings.key?(type) mappings[type]['properties'] end
mappings(&block)
click to toggle source
# File lib/cauchy/index_schema.rb, line 41 def mappings(&block) self.mappings = block.call || {} if block_given? @mappings || {} end
mappings=(value)
click to toggle source
# File lib/cauchy/index_schema.rb, line 46 def mappings=(value) @mappings = value.map do |type, mapping| [type.to_s, normalize_mapping(mapping)] end.to_h end
settings(&block)
click to toggle source
# File lib/cauchy/index_schema.rb, line 57 def settings(&block) self.settings = block.call || {} if block_given? @settings || {} end
settings=(value)
click to toggle source
# File lib/cauchy/index_schema.rb, line 62 def settings=(value) @settings = normalize_settings(value) end
types()
click to toggle source
# File lib/cauchy/index_schema.rb, line 66 def types mappings.keys end
version()
click to toggle source
# File lib/cauchy/index_schema.rb, line 70 def version @version ||= Digest::SHA1.hexdigest( { settings: settings, mappings: mappings }.to_json ) end