Support Ruby 2.4.

This commit is contained in:
Guo Xiang Tan
2017-04-15 12:11:02 +08:00
parent 86efc57390
commit 04016f0dec
29 changed files with 73 additions and 60 deletions

View File

@ -23,7 +23,7 @@ module SiteSettingExtension
def types
@types ||= Enum.new(string: 1,
time: 2,
fixnum: 3,
integer: 3,
float: 4,
bool: 5,
null: 6,
@ -286,7 +286,7 @@ module SiteSettingExtension
val = (val == "t" || val == "true") ? 't' : 'f'
end
if type == types[:fixnum] && !val.is_a?(Fixnum)
if type == types[:integer] && !val.is_a?(Integer)
val = val.to_i
end
@ -295,7 +295,7 @@ module SiteSettingExtension
end
if type == types[:enum]
val = val.to_i if defaults[name.to_sym].is_a?(Fixnum)
val = val.to_i if defaults[name.to_sym].is_a?(Integer)
if enum_class(name)
raise Discourse::InvalidParameters.new(:value) unless enum_class(name).valid_value?(val)
else
@ -340,9 +340,9 @@ module SiteSettingExtension
valid = true
type = get_data_type(name, defaults[name.to_sym])
if type == types[:fixnum]
# validate fixnum
valid = false unless value.to_i.is_a?(Fixnum)
if type == types[:integer]
# validate integer
valid = false unless value.to_i.is_a?(Integer)
end
valid
@ -407,8 +407,8 @@ module SiteSettingExtension
case val
when String
types[:string]
when Fixnum
types[:fixnum]
when Integer
types[:integer]
when Float
types[:float]
when TrueClass, FalseClass
@ -422,14 +422,14 @@ module SiteSettingExtension
case type
when types[:float]
value.to_f
when types[:fixnum]
when types[:integer]
value.to_i
when types[:bool]
value == true || value == "t" || value == "true"
when types[:null]
nil
when types[:enum]
defaults[name.to_sym].is_a?(Fixnum) ? value.to_i : value
defaults[name.to_sym].is_a?(Integer) ? value.to_i : value
else
return value if types[type]
# Otherwise it's a type error
@ -441,7 +441,7 @@ module SiteSettingExtension
@validator_mapping ||= {
'email' => EmailSettingValidator,
'username' => UsernameSettingValidator,
types[:fixnum] => IntegerSettingValidator,
types[:integer] => IntegerSettingValidator,
types[:string] => StringSettingValidator,
'list' => StringSettingValidator,
'enum' => StringSettingValidator,