lib/partitioned/partitioned_base/configurator/dsl.rb in partitioned-0.8.0 vs lib/partitioned/partitioned_base/configurator/dsl.rb in partitioned-1.0.1
- old
+ new
@@ -2,26 +2,26 @@
class PartitionedBase
module Configurator
#
# The Domain Specific Language manager for configuring partitioning.
#
- # example:
+ # @example of use:
#
- # class Employee < Partitioned::ByCreatedAt
- # partitioned do |partition|
- # partition.index :id, :unique => true
- # partition.foreign_key :company_id
+ # class Employee < Partitioned::ByCreatedAt
+ # partitioned do |partition|
+ # partition.index :id, :unique => true
+ # partition.foreign_key :company_id
+ # end
# end
- # end
#
- # in the above example, block:
+ # in the above example, block:
#
- # partitioned do |partition|
- # ...
- # end
+ # partitioned do |partition|
+ # ...
+ # end
#
- # Scopes a set of "partition directives". The directives are accessed via the block parameter 'partition'
+ # Scopes a set of "partition directives". The directives are accessed via the block parameter 'partition'
#
# Directives parameters have two forms, a canonical form which takes a set of parameters
# and a dynamic form which takes a single parameter which is either a string that should be interpolated or
# a lambda.
#
@@ -34,14 +34,15 @@
# def self.partition_time_field
# return :created_at
# end
#
# partitioned do |partition|
- # partition.on lambda{|model| return model.partition_time_field}
+ # partition.on lambda{ |model| return model.partition_time_field}
# partition.constraint lambda{|model,time_field_value|
- # return "#{model.partition_time_field} >= '#{time_field_value.strftime}' and #{model.partition_time_field} < '#{(time_field_value + 1.day).strftime}'"
- # }
+ # return "#{model.partition_time_field} >= '#{time_field_value.strftime}' and
+ # #{model.partition_time_field} < '#{(time_field_value + 1.day).strftime}'"
+ # }
# end
# end
#
# Single parameter lambdas are passed the most derived Partitioned::PartitionedBase class that defines the
# model of this partitioned table:
@@ -132,10 +133,13 @@
# Since resolution of the self occurs at lambda definition time, self is Employee instead of
# FavoriteEmployee and index_field will be :bar instead of :baz. model.index_field will
# resolve to FavoriteEmployee.index_field and be :baz as expected.
#
class Dsl
+ #
+ # raised when a partitioned DSL directive's parameters are considered invalid
+ #
class InvalidConfiguratorDirectiveValue < StandardError
def initialize(model, table_name, directive, value, explanation)
super("#{model.name} [#{table_name}] invalid value '#{value}' for partitioned directive '#{directive}'. #{explanation}")
end
end
@@ -252,10 +256,11 @@
#
def foreign_key(referencing_field, referenced_table = nil, referenced_field = :id)
if referencing_field.is_a? Proc
data.foreign_keys << referencing_field
else
- data.foreign_keys << Partitioned::PartitionedBase::Configurator::Data::ForeignKey.new(referencing_field, referenced_table, referenced_field)
+ data.foreign_keys << Partitioned::PartitionedBase::Configurator::Data::ForeignKey.
+ new(referencing_field, referenced_table, referenced_field)
end
end
#
# Define the check constraint for a given child table.