watir_model 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8a8ae5db6acadd7242a30cb2e94465d89836ef2
4
- data.tar.gz: a73eb288f801a25317cb7990989df7a962cb41d0
3
+ metadata.gz: 1d6966079e205c1a6bd488096daf9bb9197afc7c
4
+ data.tar.gz: 38203bdccf10d9dc5d5879aaac9622524db5bf35
5
5
  SHA512:
6
- metadata.gz: 973516b9347349f12845c957a131274c1245b06d65d2b6cc84b16c1d23807aa44bf0566f6fce24e0441f6b90776679a6e9dbbaf428e5d08d63bf59e9e0b2914a
7
- data.tar.gz: 1f970b12adc1ed24e006a23207f555335b728cdccdcea796f4813c4398eab1c9b725ba7e0df48fbf4a8198b43b014f095cca1a504ad6a5ea7e7fdb920396debc
6
+ metadata.gz: 44fff36c841c6db3c5eceb51fc7e7102f56007535e25525fb27bbf146d830cb9ec9795604cec9afcc53a452773079046138415f306efb8a1d6e4dd6cd5dee845
7
+ data.tar.gz: abe074605473e24846a4cf94002bbc02eac53d61605804c0ae4f956803e87476b391e5230f35486d08d557b121eec25e0b53b6644f70279d95fd140ff51ff477
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.5.5 (2018-01-20)
2
+
3
+ * allow overriding or specifying custom conversions
4
+
1
5
  ### 0.5.4 (2018-01-06)
2
6
 
3
7
  * fix bug in create method for namespaced classes
@@ -0,0 +1,48 @@
1
+ module DataConversions
2
+
3
+ def convert_string(value)
4
+ value.to_s
5
+ end
6
+
7
+ def convert_time(value)
8
+ Object.const_get(__callee__.to_s.gsub('convert_', '').camelcase).parse value
9
+ end
10
+
11
+ alias_method :convert_date, :convert_time
12
+ alias_method :convert_date_time, :convert_time
13
+
14
+ def convert_integer(value)
15
+ value.to_i
16
+ end
17
+
18
+ def convert_float(value)
19
+ value.to_f
20
+ end
21
+
22
+ def convert_boolean(value)
23
+ return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
24
+ value = eval(value)
25
+ value.is_a?(TrueClass) || value.is_a?(FalseClass) ? value : nil
26
+ end
27
+
28
+ def convert_symbol(value)
29
+ value.to_sym
30
+ end
31
+
32
+ def convert_hash(value)
33
+ value = parse_json(value)
34
+ value.to_h if value.respond_to? :to_h
35
+ end
36
+
37
+ def convert_array(value)
38
+ value = parse_json(value)
39
+ value.is_a?(Array) ? value : Array(value)
40
+ end
41
+
42
+ def parse_json(value)
43
+ value = JSON.parse value
44
+ rescue JSON::ParserError
45
+ value
46
+ end
47
+
48
+ end
data/lib/watir_model.rb CHANGED
@@ -6,10 +6,12 @@ require 'date'
6
6
  require 'time'
7
7
  require 'faker'
8
8
  require 'yml_reader'
9
+ require 'data_conversions'
9
10
 
10
11
  class WatirModel
11
12
  class << self
12
13
  include YmlReader
14
+ include DataConversions
13
15
 
14
16
  attr_writer :keys, :data_types, :defaults, :apis
15
17
 
@@ -52,32 +54,15 @@ class WatirModel
52
54
  data_type = data_types[key]
53
55
  return value if data_type.nil?
54
56
  return value if data_type.is_a?(Class) && value.is_a?(data_type)
55
- value = case
56
- when data_type == String
57
- value.to_s
58
- when [Time, Date, DateTime].include?(data_type)
59
- data_type.parse value
60
- when data_type == Integer
61
- value.to_i
62
- when data_type == Float
63
- value.to_f
64
- when data_type == :boolean
65
- return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
66
- value = eval(value)
67
- return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
68
- raise StandardError, "Unable to convert #{value} to TrueClass or FalseClass"
69
- when data_type == Symbol
70
- value.to_sym
71
- when data_type == Hash
72
- JSON.parse value
73
- when data_type == Array
74
- JSON.parse value
57
+ method = "convert_#{data_type.to_s.underscore}"
58
+ value = if respond_to? method
59
+ send(method, value)
75
60
  else
76
61
  file = factory_file(data_type)
77
62
  data = data_from_yaml(file, value) || value
78
63
  data_type.new(data)
79
64
  end
80
- return value if value.is_a?(data_type)
65
+ return value unless value.nil?
81
66
  raise StandardError, "Unable to convert #{value} to #{data_type}"
82
67
  end
83
68
 
data/watir_model.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "watir_model"
5
- spec.version = "0.5.4"
5
+ spec.version = "0.5.5"
6
6
  spec.authors = ["Titus Fortner"]
7
7
  spec.email = ["titusfortner@gmail.com"]
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-06 00:00:00.000000000 Z
11
+ date: 2018-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -112,6 +112,7 @@ files:
112
112
  - config/data/address.yml
113
113
  - config/data/default_model.yml
114
114
  - lib/config_model.rb
115
+ - lib/data_conversions.rb
115
116
  - lib/watir_model.rb
116
117
  - watir_model.gemspec
117
118
  homepage: https://github.com/titusfortner/watir_model