class NoSE::WorkloadDSL
A helper class for DSL
creation to avoid messing with {Workload}
Public Class Methods
new(arg)
click to toggle source
# File lib/nose/workload.rb, line 144 def initialize(arg) if arg.is_a? Workload @workload = arg @model = arg.model elsif arg.is_a? Model @model = arg end end
Public Instance Methods
DefaultMix(mix)
click to toggle source
Allow setting the default workload mix @return [void]
# File lib/nose/workload.rb, line 206 def DefaultMix(mix) @workload.mix = mix end
Entity(*args, &block)
click to toggle source
Shortcut to add a new {Entity} to the workload @return [Entity]
# File lib/nose/workload.rb, line 162 def Entity(*args, &block) @model.add_entity Entity.new(*args, &block) end
Group(name, weight = 1.0, **mixes, &block)
click to toggle source
Allow grouping statements with an associated weight @return [void]
# File lib/nose/workload.rb, line 212 def Group(name, weight = 1.0, **mixes, &block) fail 'Groups require a workload' if @workload.nil? # Apply the DSL dsl = GroupDSL.new dsl.instance_eval(&block) if block_given? dsl.statements.each do |statement| Q(statement, weight, **mixes, group: name) end end
HasMany(from_name, to_name, entities, **options)
click to toggle source
HasOne(from_name, to_name, entities, **options)
click to toggle source
Separate function for foreign keys to avoid circular dependencies @return [void]
# File lib/nose/workload.rb, line 174 def HasOne(from_name, to_name, entities, **options) from_entity, to_entity = entities.first from_field = Fields::ForeignKeyField.new from_name, @model[to_entity], **options # Add the key in the opposite direction options[:count] = @model[from_entity].count options[:relationship] = :many to_field = Fields::ForeignKeyField.new to_name, @model[from_entity], **options # Set the opposite keys and add to entities to_field.reverse = from_field from_field.reverse = to_field @model[from_entity] << from_field @model[to_entity] << to_field end
Model(name)
click to toggle source
Allow the use of an external model
# File lib/nose/workload.rb, line 156 def Model(name) @workload.instance_variable_set(:@model, NoSE::Model.load(name)) end
Q(statement, weight = 1.0, group: nil, label: nil, **mixes)
click to toggle source
Shortcut to add a new {Statement} to the workload @return [void]
# File lib/nose/workload.rb, line 196 def Q(statement, weight = 1.0, group: nil, label: nil, **mixes) fail 'Statements require a workload' if @workload.nil? return if weight.zero? && mixes.empty? mixes = { default: weight } if mixes.empty? @workload.add_statement statement, mixes, group: group, label: label end