typero 0.4.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +0,0 @@
1
- class Typero::FloatType < Typero::Type
2
-
3
- def set
4
- @value = @value.to_f
5
- end
6
-
7
- def validate
8
- raise TypeError, error_for(:min_length_error) % @opts[:min] if @opts[:min] && value < @opts[:min]
9
- raise TypeError, error_for(:max_length_error) % @opts[:max] if @opts[:max] && value > @opts[:max]
10
- end
11
-
12
- def min_length_error
13
- "min lenght is %s"
14
- end
15
-
16
- def max_length_error
17
- "max lenght is %s"
18
- end
19
-
20
- end
21
-
@@ -1,14 +0,0 @@
1
- class Typero::HashType < Typero::Type
2
- def default
3
- {}
4
- end
5
-
6
- def validate
7
- raise TypeError, error_for(:not_hash_type_error) unless @value.is_a?(Hash)
8
- end
9
-
10
- def not_hash_type_error
11
- 'value is not hash type'
12
- end
13
- end
14
-
@@ -1,19 +0,0 @@
1
- class Typero::IntegerType < Typero::Type
2
- def set
3
- @value = @value.to_i
4
- end
5
-
6
- def validate
7
- raise TypeError, error_for(:min_value_error) % [@opts[:min], @value] if @opts[:min] && @value < @opts[:min]
8
- raise TypeError, error_for(:max_value_error) % [@opts[:max], @value] if @opts[:max] && @value > @opts[:max]
9
- end
10
-
11
- def min_value_error
12
- 'min is %s, got %s'
13
- end
14
-
15
- def max_value_error
16
- 'max is %s, got %s'
17
- end
18
- end
19
-
@@ -1,13 +0,0 @@
1
- class Typero::LabelType < Typero::Type
2
- def set
3
- @value = @value.to_s.gsub(/\s+/,'-').gsub(/[^\w\-]/,'').gsub(/\-+/, '-')[0,30].downcase
4
- end
5
-
6
- def validate
7
- raise TypeError, error_for(:unallowed_characters_error) unless @value =~ /^[\w\-]+$/
8
- end
9
-
10
- def unallowed_characters_error
11
- 'label is having unallowed characters'
12
- end
13
- end
@@ -1,22 +0,0 @@
1
- class Typero::StringType < Typero::Type
2
- def set
3
- @value = @value.to_s unless @value.is_a?(String)
4
- @value = @value.downcase if @opts[:downcase]
5
- end
6
-
7
- def validate
8
- raise TypeError, error_for(:min_length_error) % [@opts[:min], @value.length] if @opts[:min] && @value.length < @opts[:min]
9
- raise TypeError, error_for(:max_length_error) % [@opts[:max], @value.length] if @opts[:max] && @value.length > @opts[:max]
10
- end
11
-
12
- # ready for localization
13
-
14
- def min_length_error
15
- 'min lenght is %s, you have %s'
16
- end
17
-
18
- def max_length_error
19
- 'max lenght is %s, you have %s'
20
- end
21
- end
22
-
@@ -1,14 +0,0 @@
1
- class Typero::UrlType < Typero::Type
2
- def set
3
- @value = 'http://%s' % @value unless @value.include?('://')
4
- end
5
-
6
- def validate
7
- raise TypeError, error_for(:not_starting_error) unless @value =~ /^https?:\/\/./
8
- end
9
-
10
- def not_starting_error
11
- 'URL is not starting with http'
12
- end
13
- end
14
-