Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/avram/callbacks/after_commit_callback.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module Avram::AfterCommitCallback
{% end %}
{%
if block.args.size != 1
raise <<-ERR
block.raise <<-ERR
The 'after_commit' callback requires exactly 1 block arg to be passed.
Example:
after_commit do |saved_user|
Expand Down
2 changes: 1 addition & 1 deletion src/avram/callbacks/callbacks.cr
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module Avram::Callbacks
macro after_run(&block)
{%
if block.args.size != 1
raise <<-ERR
block.raise <<-ERR
The 'after_run' callback requires exactly 1 block arg to be passed.
Example:
after_run { |value| some_method(value) }
Expand Down
2 changes: 1 addition & 1 deletion src/avram/callbacks/delete_callbacks.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module Avram::DeleteCallbacks
{% end %}
{%
if block.args.size != 1
raise <<-ERR
block.raise <<-ERR
The 'after_delete' callback requires exactly 1 block arg to be passed.
Example:
after_delete do |deleted_user|
Expand Down
2 changes: 1 addition & 1 deletion src/avram/callbacks/save_callbacks.cr
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module Avram::SaveCallbacks
{% end %}
{%
if block.args.size != 1
raise <<-ERR
block.raise <<-ERR
The 'after_save' callback requires exactly 1 block arg to be passed.
Example:
after_save do |saved_user|
Expand Down
5 changes: 3 additions & 2 deletions src/avram/define_attribute.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ module Avram::DefineAttribute
{% else %}
{% default_value = "= #{type_declaration.value}" %}
{% end %}
{% raise <<-ERROR

{% type_declaration.type.raise <<-ERROR
`attribute` in #{@type} must not be called with a type union or nilable type but was called with #{type_declaration.type}
If you were attempting to create a nilable attribute, all attributes are considered nilable by default.

Expand Down Expand Up @@ -89,7 +90,7 @@ module Avram::DefineAttribute

macro file_attribute(key)
{% unless key.is_a?(SymbolLiteral) %}
{% raise "file_attribute must be declared with a Symbol" %}
{% key.raise "file_attribute must be declared with a Symbol" %}
{% end %}

attribute {{ key.id }} : Avram::Uploadable
Expand Down
11 changes: 5 additions & 6 deletions src/avram/migrator/alter_table_statement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Avram::Migrator::AlterTableStatement
macro change_type(type_declaration, **type_options)
{%
if !type_declaration.is_a?(TypeDeclaration)
raise "Must pass a type declaration to 'change_type'. Example: change_type age : Int32"
type_declaration.raise "Must pass a type declaration to 'change_type'. Example: change_type age : Int32"
elsif type_options.keys.includes?("default".id)
raise "Cannot change the default value from `change_type`. Use `change_default` instead."
end
Expand Down Expand Up @@ -70,7 +70,7 @@ class Avram::Migrator::AlterTableStatement
macro change_default(type_declaration, default)
{%
if !type_declaration.is_a?(TypeDeclaration)
raise "Must pass a type declaration to 'change_default'. Example: change_default count : Int32, default: 1"
type_declaration.raise "Must pass a type declaration to 'change_default'. Example: change_default count : Int32, default: 1"
end
%}
%column = ::Avram::Migrator::Columns::{{ type_declaration.type }}Column({{ type_declaration.type }}).new(
Expand Down Expand Up @@ -176,10 +176,10 @@ class Avram::Migrator::AlterTableStatement
# Adds a references column and index given a model class and references option.
macro add_belongs_to(type_declaration, on_delete, references = nil, foreign_key_type = Int64, fill_existing_with = nil, unique = false, index = true)
{% unless type_declaration.is_a?(TypeDeclaration) %}
{% raise "add_belongs_to expected a type declaration like 'user : User', instead got: '#{type_declaration}'" %}
{% type_declaration.raise "add_belongs_to expected a type declaration like 'user : User', instead got: '#{type_declaration}'" %}
{% end %}
{% if type_declaration.type.stringify =~ /\w::\w/ && references.nil? %}
{% raise <<-ERROR
{% type_declaration.raise <<-ERROR
Namespaced models must include the `references` option with the name of the table.

Try this...
Expand Down Expand Up @@ -297,14 +297,13 @@ class Avram::Migrator::AlterTableStatement
end

macro symbol_expected_error(action, name)

{% if name.is_a?(TypeDeclaration) %}
{% example = name.var %}
{% else %}
{% example = name.id %}
{% end %}

{% raise <<-ERROR
{% name.raise <<-ERROR

#{action} expected a symbol like :#{example}, instead got: #{name}.

Expand Down
4 changes: 2 additions & 2 deletions src/avram/migrator/create_table_statement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ class Avram::Migrator::CreateTableStatement
# Adds a references column and index given a model class and references option.
macro add_belongs_to(type_declaration, on_delete, references = nil, foreign_key_type = Int64, unique = false, index = true)
{% unless type_declaration.is_a?(TypeDeclaration) %}
{% raise "add_belongs_to expected a type declaration like 'user : User', instead got: '#{type_declaration}'" %}
{% type_declaration.raise "add_belongs_to expected a type declaration like 'user : User', instead got: '#{type_declaration}'" %}
{% end %}
{% if type_declaration.type.stringify =~ /\w::\w/ && references.nil? %}
{% raise <<-ERROR
{% type_declaration.raise <<-ERROR
Namespaced models must include the `references` option with the name of the table.

Try this...
Expand Down
2 changes: 1 addition & 1 deletion src/avram/model.cr
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ abstract class Avram::Model
{% value_generator = type_declaration.value %}

{% if !value_generator || value_generator && !(value_generator.is_a?(ProcLiteral) || value_generator.is_a?(ProcPointer) || value_generator.is_a?(Call)) %}
{% raise <<-ERROR
{% type_declaration.type.raise <<-ERROR
When using a String primary_key, you must also specify a way to generate the value.
You can provide a class method, a proc or a proc pointer.
Your value generator must return a non-nullable String.
Expand Down
2 changes: 1 addition & 1 deletion src/avram/nested_save_operation.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Avram::NestedSaveOperation
end %}

{% unless assoc %}
{% raise "#{T} must have a has_one association with #{model_type}" %}
{% type_declaration.raise "#{T} must have a has_one association with #{model_type}" %}
{% end %}

@_{{ name }} : {{ type }} | Nil
Expand Down
6 changes: 3 additions & 3 deletions src/avram/save_operation.cr
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ abstract class Avram::SaveOperation(T)
macro permit_columns(*attribute_names)
{% for attribute_name in attribute_names %}
{% if attribute_name.is_a?(TypeDeclaration) %}
{% raise <<-ERROR
{% attribute_name.raise <<-ERROR
Must use a Symbol or a bare word in 'permit_columns'. Instead, got: #{attribute_name}

Try this...
Expand All @@ -163,7 +163,7 @@ abstract class Avram::SaveOperation(T)
%}
{% end %}
{% unless attribute_name.is_a?(SymbolLiteral) || attribute_name.is_a?(Call) %}
{% raise <<-ERROR
{% attribute_name.raise <<-ERROR
Must use a Symbol or a bare word in 'permit_columns'. Instead, got: #{attribute_name}

Try this...
Expand All @@ -181,7 +181,7 @@ abstract class Avram::SaveOperation(T)

@@permitted_param_keys << "{{ attribute_name.id }}"
{% else %}
{% raise <<-ERROR
{% attribute_name.raise <<-ERROR
Can't permit '#{attribute_name}' because the column has not been defined on the model for #{@type}.

Try this...
Expand Down
Loading