Module: VWO::Common::Validations
- Included in:
- VWO, BucketingService, DecisionService, GetSettings
- Defined in:
- lib/vwo/common/validations.rb
Constant Summary collapse
- UTILITIES =
{ 'logger' => ['log'], 'event_dispatcher' => ['dispatch'], 'user_profile_service' => %w[lookup save] }.freeze
Instance Method Summary collapse
- #valid_hash?(val) ⇒ Boolean
- #valid_number?(val) ⇒ Boolean
-
#valid_settings_file?(settings_file) ⇒ Boolean
Validates the project settings_file.
- #valid_string?(val) ⇒ Boolean
- #valid_utility?(utility, utility_name) ⇒ Boolean
- #valid_value?(val) ⇒ Boolean
Instance Method Details
#valid_hash?(val) ⇒ Boolean
42 43 44 |
# File 'lib/vwo/common/validations.rb', line 42 def valid_hash?(val) val.is_a?(Hash) end |
#valid_number?(val) ⇒ Boolean
32 33 34 |
# File 'lib/vwo/common/validations.rb', line 32 def valid_number?(val) val.is_a?(Numeric) end |
#valid_settings_file?(settings_file) ⇒ Boolean
Validates the project settings_file
19 20 21 22 23 24 |
# File 'lib/vwo/common/validations.rb', line 19 def valid_settings_file?(settings_file) settings_file = JSON.parse(settings_file) JSON::Validator.validate!(VWO::Common::Schema::SETTINGS_FILE_SCHEMA, settings_file) rescue StandardError false end |
#valid_string?(val) ⇒ Boolean
37 38 39 |
# File 'lib/vwo/common/validations.rb', line 37 def valid_string?(val) val.is_a?(String) end |
#valid_utility?(utility, utility_name) ⇒ Boolean
49 50 51 52 53 54 55 56 57 |
# File 'lib/vwo/common/validations.rb', line 49 def valid_utility?(utility, utility_name) utility_attributes = UTILITIES[utility_name] return false if utility_attributes.nil? utility_attributes.each do |attr| return false unless method?(utility, attr) end true end |
#valid_value?(val) ⇒ Boolean
27 28 29 |
# File 'lib/vwo/common/validations.rb', line 27 def valid_value?(val) !val.nil? end |