schematic 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -8
- data/.travis.yml +17 -0
- data/Gemfile +6 -1
- data/LICENSE +1 -1
- data/README.md +106 -0
- data/Rakefile +3 -8
- data/lib/schematic.rb +3 -42
- data/lib/schematic/exceptions.rb +13 -0
- data/lib/schematic/generator/column.rb +17 -11
- data/lib/schematic/generator/namespaces.rb +3 -3
- data/lib/schematic/generator/restrictions/base.rb +5 -5
- data/lib/schematic/generator/restrictions/custom.rb +3 -2
- data/lib/schematic/generator/restrictions/enumeration.rb +5 -2
- data/lib/schematic/generator/restrictions/length.rb +4 -2
- data/lib/schematic/generator/restrictions/numericality.rb +3 -1
- data/lib/schematic/generator/restrictions/pattern.rb +4 -3
- data/lib/schematic/generator/sandbox.rb +4 -1
- data/lib/schematic/generator/types.rb +14 -13
- data/lib/schematic/generator/uniqueness.rb +7 -8
- data/lib/schematic/generator/xsd.rb +32 -26
- data/lib/schematic/serializers/xsd.rb +6 -6
- data/lib/schematic/version.rb +1 -1
- data/schematic.gemspec +23 -24
- data/spec/schematic/generator/restrictions/custom_spec.rb +15 -18
- data/spec/schematic/generator/restrictions/enumeration_spec.rb +31 -31
- data/spec/schematic/generator/restrictions/length_spec.rb +35 -30
- data/spec/schematic/generator/restrictions/mixin_spec.rb +11 -15
- data/spec/schematic/generator/restrictions/numericality_spec.rb +11 -11
- data/spec/schematic/generator/restrictions/pattern_spec.rb +20 -21
- data/spec/schematic/generator/sandbox_spec.rb +17 -17
- data/spec/schematic/generator/uniqueness_spec.rb +38 -37
- data/spec/schematic/serializers/xsd_extend_spec.rb +11 -11
- data/spec/schematic/serializers/xsd_validation_presence_spec.rb +16 -11
- data/spec/schematic/serializers/xsd_xsd_ignore_methods_spec.rb +3 -3
- data/spec/schematic/serializers/xsd_xsd_methods_spec.rb +27 -24
- data/spec/schematic/serializers/xsd_xsd_minimum_occurrences_for_spec.rb +13 -8
- data/spec/schematic_serializers_xsd_spec.rb +70 -67
- data/spec/spec_helper.rb +8 -113
- data/spec/support/database.rb +9 -0
- data/spec/support/helpers.rb +111 -0
- data/spec/support/with_model.rb +5 -0
- data/spec/{xsd → support/xsd}/XMLSchema.xsd +0 -0
- data/spec/{xsd → support/xsd}/xml.xsd +0 -0
- metadata +54 -69
- data/.rspec +0 -1
- data/.rvmrc +0 -1
- data/README.rdoc +0 -103
- data/spec/support/extensions/active_model/validations/inclusion.rb +0 -69
@@ -1,69 +0,0 @@
|
|
1
|
-
#This backports Rails 3.1 lambda inclusion behavior for Rails 3.
|
2
|
-
require 'active_support/core_ext/range'
|
3
|
-
|
4
|
-
module ActiveModel
|
5
|
-
|
6
|
-
# == Active Model Inclusion Validator
|
7
|
-
module Validations
|
8
|
-
class InclusionValidator < EachValidator
|
9
|
-
def check_validity!
|
10
|
-
unless [:include?, :call].any?{ |method| options[:in].respond_to?(method) }
|
11
|
-
error_message = "An object with the method #include? or a proc or lambda is required, " <<
|
12
|
-
"and must be supplied as the :in option of the configuration hash"
|
13
|
-
raise ArgumentError, error_message
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def validate_each(record, attribute, value)
|
18
|
-
delimiter = options[:in]
|
19
|
-
exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
|
20
|
-
unless exclusions.send(inclusion_method(exclusions), value)
|
21
|
-
record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
# In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible values in the
|
28
|
-
# range for equality, so it may be slow for large ranges. The new <tt>Range#cover?</tt>
|
29
|
-
# uses the previous logic of comparing a value with the range endpoints.
|
30
|
-
def inclusion_method(enumerable)
|
31
|
-
enumerable.is_a?(Range) ? :cover? : :include?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module HelperMethods
|
36
|
-
# Validates whether the value of the specified attribute is available in a particular enumerable object.
|
37
|
-
#
|
38
|
-
# class Person < ActiveRecord::Base
|
39
|
-
# validates_inclusion_of :gender, :in => %w( m f )
|
40
|
-
# validates_inclusion_of :age, :in => 0..99
|
41
|
-
# validates_inclusion_of :format, :in => %w( jpg gif png ), :message => "extension %{value} is not included in the list"
|
42
|
-
# validates_inclusion_of :states, :in => lambda{ |person| STATES[person.country] }
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# Configuration options:
|
46
|
-
# * <tt>:in</tt> - An enumerable object of available items. This can be
|
47
|
-
# supplied as a proc or lambda which returns an enumerable. If the enumerable
|
48
|
-
# is a range the test is performed with <tt>Range#cover?</tt>
|
49
|
-
# (backported in Active Support for 1.8), otherwise with <tt>include?</tt>.
|
50
|
-
# * <tt>:message</tt> - Specifies a custom error message (default is: "is not included in the list").
|
51
|
-
# * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
|
52
|
-
# * <tt>:allow_blank</tt> - If set to true, skips this validation if the attribute is blank (default is +false+).
|
53
|
-
# * <tt>:on</tt> - Specifies when this validation is active. Runs in all
|
54
|
-
# validation contexts by default (+nil+), other options are <tt>:create</tt>
|
55
|
-
# and <tt>:update</tt>.
|
56
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
|
57
|
-
# occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
|
58
|
-
# method, proc or string should return or evaluate to a true or false value.
|
59
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
|
60
|
-
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
61
|
-
# method, proc or string should return or evaluate to a true or false value.
|
62
|
-
def validates_inclusion_of(*attr_names)
|
63
|
-
validates_with InclusionValidator, _merge_attributes(attr_names)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
|