Skip to content

Commit

Permalink
Merge branch 'master' into 0.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jul 22, 2016
2 parents 415bf0c + f04536c commit 593d1eb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Hanami::Validations
Validations mixin for Ruby objects

## v0.6.0 - (unreleased)
## v0.6.0 - 2016-07-22
### Added
- [Luca Guidi] Predicates syntax
- [Luca Guidi] Custom predicates
Expand Down
30 changes: 15 additions & 15 deletions lib/hanami/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Hanami
# end
# end
module Validations
# @since x.x.x
# @since 0.6.0
# @api private
DEFAULT_MESSAGES_ENGINE = :yaml

Expand Down Expand Up @@ -65,7 +65,7 @@ module ClassMethods
#
# @param blk [Proc] validation rules
#
# @since x.x.x
# @since 0.6.0
#
# @example
# require 'hanami/validations'
Expand Down Expand Up @@ -100,7 +100,7 @@ def validations(&blk)
#
# @return nil
#
# @since x.x.x
# @since 0.6.0
#
# @example Without Custom Message
# require 'hanami/validations'
Expand Down Expand Up @@ -145,7 +145,7 @@ def predicate(name, message: 'is invalid', &blk)
#
# @param mod [Module] a module with shared predicates
#
# @since x.x.x
# @since 0.6.0
#
# @see Hanami::Validations::Predicates
#
Expand Down Expand Up @@ -178,7 +178,7 @@ def predicates(mod)
#
# @param type [Symbol] the preferred engine
#
# @since x.x.x
# @since 0.6.0
#
# @example
# require 'hanami/validations'
Expand All @@ -196,7 +196,7 @@ def messages(type)
#
# @param path [String] path to translation file
#
# @since x.x.x
# @since 0.6.0
#
# @example
# require 'hanami/validations'
Expand All @@ -214,7 +214,7 @@ def messages_path(path)
#
# @param name [String] namespace
#
# @since x.x.x
# @since 0.6.0
#
# @example
# require 'hanami/validations'
Expand Down Expand Up @@ -243,27 +243,27 @@ def namespace(name = nil)

private

# @since x.x.x
# @since 0.6.0
# @api private
def _build(options = {}, &blk)
options = { build: false }.merge(options)
Dry::Validation.__send__(_schema_type, options, &blk)
end

# @since x.x.x
# @since 0.6.0
# @api private
def _schema_type
:Schema
end

# @since x.x.x
# @since 0.6.0
# @api private
def _base_rules
lambda do
end
end

# @since x.x.x
# @since 0.6.0
# @api private
def _schema_config
lambda do |config|
Expand All @@ -273,7 +273,7 @@ def _schema_config
end
end

# @since x.x.x
# @since 0.6.0
# @api private
def _schema_predicates
return if _predicates_module.nil? && _predicates.empty?
Expand All @@ -284,7 +284,7 @@ def _schema_predicates
end
end

# @since x.x.x
# @since 0.6.0
# @api private
def __predicates
mod = Module.new { include Hanami::Validations::Predicates }
Expand All @@ -298,7 +298,7 @@ def __predicates
mod
end

# @since x.x.x
# @since 0.6.0
# @api private
# rubocop:disable Metrics/MethodLength
def __messages
Expand Down Expand Up @@ -329,7 +329,7 @@ def messages
#
# @param input [#to_h] a set of input data
#
# @since x.x.x
# @since 0.6.0
def initialize(input = {})
@input = input.to_h
end
Expand Down
8 changes: 4 additions & 4 deletions lib/hanami/validations/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Validations
# This must be used when the input comes from a browser or an HTTP endpoint.
# It knows how to deal with common data types, and common edge cases like blank strings.
#
# @since x.x.x
# @since 0.6.0
#
# @example
# require 'hanami/validations/form'
Expand All @@ -20,7 +20,7 @@ module Form
#
# @param base [Class] the target action
#
# @since x.x.x
# @since 0.6.0
# @api private
#
# @see http://www.ruby-doc.org/core/Module.html#method-i-included
Expand All @@ -31,12 +31,12 @@ def self.included(base)
end
end

# @since x.x.x
# @since 0.6.0
# @api private
module ClassMethods
private

# @since x.x.x
# @since 0.6.0
# @api private
def _schema_type
:Form
Expand Down
12 changes: 6 additions & 6 deletions lib/hanami/validations/inline_predicate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ module Hanami
module Validations
# Inline predicate
#
# @since x.x.x
# @since 0.6.0
# @api private
class InlinePredicate
# @since x.x.x
# @since 0.6.0
# @api private
attr_reader :name

# @since x.x.x
# @since 0.6.0
# @api private
attr_reader :message

Expand All @@ -21,21 +21,21 @@ class InlinePredicate
#
# @return [Hanami::Validations::InlinePredicate] a new instance
#
# @since x.x.x
# @since 0.6.0
# @api private
def initialize(name, message, &blk)
@name = name
@message = message
@blk = blk
end

# @since x.x.x
# @since 0.6.0
# @api private
def to_proc
@blk
end

# @since x.x.x
# @since 0.6.0
# @api private
def ==(other)
self.class == other.class &&
Expand Down
20 changes: 10 additions & 10 deletions lib/hanami/validations/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ module Validations
# For a given `FooValidator` class, it will look for I18n messages within
# the `foo` group.
#
# @since x.x.x
# @since 0.6.0
# @api private
class Namespace
# @since x.x.x
# @since 0.6.0
# @api private
SUFFIX = 'Validator'.freeze

# @since x.x.x
# @since 0.6.0
# @api private
SUFFIX_REPLACEMENT = ''.freeze

# @since x.x.x
# @since 0.6.0
# @api private
RUBY_NAMESPACE_SEPARATOR = '/'.freeze

# @since x.x.x
# @since 0.6.0
# @api private
RUBY_NAMESPACE_REPLACEMENT = '.'.freeze

# @since x.x.x
# @since 0.6.0
# @api private
def self.new(name, klass)
result = name || klass.name
Expand All @@ -35,27 +35,27 @@ def self.new(name, klass)
super(result)
end

# @since x.x.x
# @since 0.6.0
# @api private
def initialize(name)
@name = name
end

# @since x.x.x
# @since 0.6.0
# @api private
def to_s
underscored_name.gsub(RUBY_NAMESPACE_SEPARATOR, RUBY_NAMESPACE_REPLACEMENT)
end

private

# @since x.x.x
# @since 0.6.0
# @api private
def underscored_name
Utils::String.new(name_without_suffix).underscore
end

# @since x.x.x
# @since 0.6.0
# @api private
def name_without_suffix
@name.sub(SUFFIX, SUFFIX_REPLACEMENT)
Expand Down
4 changes: 2 additions & 2 deletions lib/hanami/validations/predicates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Hanami
module Validations
# Mixin to include when defining shared predicates
#
# @since x.x.x
# @since 0.6.0
#
# @see Hanami::Validations::ClassMethods#predicates
#
Expand All @@ -29,7 +29,7 @@ module Validations
# end
# end
module Predicates
# @since x.x.x
# @since 0.6.0
# @api private
def self.included(base)
base.class_eval do
Expand Down

0 comments on commit 593d1eb

Please sign in to comment.