class NoSE::Schema

Simple DSL for constructing indexes

Attributes

indexes[R]
model[R]

Public Class Methods

load(name) click to toggle source

Find the schema with the given name

# File lib/nose/schema.rb, line 14
def self.load(name)
  filename = File.expand_path "../../../schemas/#{name}.rb", __FILE__
  contents = File.read(filename)
  binding.eval contents, filename
end
new(&block) click to toggle source
# File lib/nose/schema.rb, line 8
def initialize(&block)
  @indexes = {}
  instance_eval(&block) if block_given?
end

Public Instance Methods

Index(key, &block) click to toggle source

Wrap commands for defining index attributes @return [void]

# File lib/nose/schema.rb, line 37
def Index(key, &block)
  # Apply the DSL
  dsl = IndexDSL.new(self)
  dsl.instance_eval(&block) if block_given?
  index = Index.new dsl.hash_fields, dsl.order_fields, dsl.extra,
                    QueryGraph::Graph.from_path(dsl.path_keys),
                    saved_key: key
  @indexes[index.key] = index
end
Model(name) click to toggle source

Set the model to be used by the schema @return [void]

# File lib/nose/schema.rb, line 24
def Model(name)
  @model = Model.load name
  NoSE::DSL.mixin_fields @model.entities, IndexDSL
end
SimpleIndex(entity) click to toggle source

Add a simple index for an entity @return [void]

# File lib/nose/schema.rb, line 31
def SimpleIndex(entity)
  @indexes[entity] = @model[entity].simple_index
end