schematic 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -8
  3. data/.travis.yml +17 -0
  4. data/Gemfile +6 -1
  5. data/LICENSE +1 -1
  6. data/README.md +106 -0
  7. data/Rakefile +3 -8
  8. data/lib/schematic.rb +3 -42
  9. data/lib/schematic/exceptions.rb +13 -0
  10. data/lib/schematic/generator/column.rb +17 -11
  11. data/lib/schematic/generator/namespaces.rb +3 -3
  12. data/lib/schematic/generator/restrictions/base.rb +5 -5
  13. data/lib/schematic/generator/restrictions/custom.rb +3 -2
  14. data/lib/schematic/generator/restrictions/enumeration.rb +5 -2
  15. data/lib/schematic/generator/restrictions/length.rb +4 -2
  16. data/lib/schematic/generator/restrictions/numericality.rb +3 -1
  17. data/lib/schematic/generator/restrictions/pattern.rb +4 -3
  18. data/lib/schematic/generator/sandbox.rb +4 -1
  19. data/lib/schematic/generator/types.rb +14 -13
  20. data/lib/schematic/generator/uniqueness.rb +7 -8
  21. data/lib/schematic/generator/xsd.rb +32 -26
  22. data/lib/schematic/serializers/xsd.rb +6 -6
  23. data/lib/schematic/version.rb +1 -1
  24. data/schematic.gemspec +23 -24
  25. data/spec/schematic/generator/restrictions/custom_spec.rb +15 -18
  26. data/spec/schematic/generator/restrictions/enumeration_spec.rb +31 -31
  27. data/spec/schematic/generator/restrictions/length_spec.rb +35 -30
  28. data/spec/schematic/generator/restrictions/mixin_spec.rb +11 -15
  29. data/spec/schematic/generator/restrictions/numericality_spec.rb +11 -11
  30. data/spec/schematic/generator/restrictions/pattern_spec.rb +20 -21
  31. data/spec/schematic/generator/sandbox_spec.rb +17 -17
  32. data/spec/schematic/generator/uniqueness_spec.rb +38 -37
  33. data/spec/schematic/serializers/xsd_extend_spec.rb +11 -11
  34. data/spec/schematic/serializers/xsd_validation_presence_spec.rb +16 -11
  35. data/spec/schematic/serializers/xsd_xsd_ignore_methods_spec.rb +3 -3
  36. data/spec/schematic/serializers/xsd_xsd_methods_spec.rb +27 -24
  37. data/spec/schematic/serializers/xsd_xsd_minimum_occurrences_for_spec.rb +13 -8
  38. data/spec/schematic_serializers_xsd_spec.rb +70 -67
  39. data/spec/spec_helper.rb +8 -113
  40. data/spec/support/database.rb +9 -0
  41. data/spec/support/helpers.rb +111 -0
  42. data/spec/support/with_model.rb +5 -0
  43. data/spec/{xsd → support/xsd}/XMLSchema.xsd +0 -0
  44. data/spec/{xsd → support/xsd}/xml.xsd +0 -0
  45. metadata +54 -69
  46. data/.rspec +0 -1
  47. data/.rvmrc +0 -1
  48. data/README.rdoc +0 -103
  49. 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
-