watir_model 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +16 -0
- data/LICENSE +1 -1
- data/lib/config_model.rb +7 -0
- data/lib/watir_model.rb +22 -50
- data/watir_model.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93dd97375c9cde4f1f0248a82f41112b20ac2c70
|
4
|
+
data.tar.gz: 95284dab556334ff3ef5bf1cf1cab1764801d4f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55e94841ba3795a67b045325c235ff7e5295200f9ef4dbce1f983bc54c42fc80c888140b8f8e68e91dd4df953deb1fa161e7d3f1a6a2b55943dcc300270c4999
|
7
|
+
data.tar.gz: 02520b948b3879bd9702d4dad4fd5553c0e0fb47f3af896abc7bf1ce4dcfcc5ce65df7a49f7ce744195ce062aa8512603915044eff1626fd2fa0e14cb0e26fd1
|
data/CHANGES.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
### 0.3.0 (2016-12-31)
|
2
|
+
|
3
|
+
* move ENV variable override into ConfigModel subclass
|
4
|
+
* remove support for specifying data types
|
5
|
+
* implement #convert method
|
6
|
+
|
7
|
+
### 0.2.3 (2016-12-22)
|
8
|
+
|
9
|
+
* Support for #to_hash
|
10
|
+
|
11
|
+
### 0.2.2 (2016-02-15)
|
12
|
+
|
13
|
+
* fork from https://github.com/bret/model
|
14
|
+
* rename model to watir_model
|
15
|
+
* support for specifying data types
|
16
|
+
* ENV variables override supplied defaults in Model
|
data/LICENSE
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
3
|
Copyright (c) 2015 Bret Pettichord
|
4
|
-
Copyright (c) 2016 Titus Fortner
|
4
|
+
Copyright (c) 2016-2017 Titus Fortner
|
5
5
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
data/lib/config_model.rb
ADDED
data/lib/watir_model.rb
CHANGED
@@ -3,16 +3,12 @@ require 'pp'
|
|
3
3
|
class WatirModel
|
4
4
|
class << self
|
5
5
|
|
6
|
-
attr_writer :keys, :
|
6
|
+
attr_writer :keys, :defaults
|
7
7
|
|
8
8
|
def keys
|
9
9
|
@keys ||= []
|
10
10
|
end
|
11
11
|
|
12
|
-
def data_types
|
13
|
-
@data_types ||= {}
|
14
|
-
end
|
15
|
-
|
16
12
|
def defaults
|
17
13
|
@defaults ||= {}
|
18
14
|
end
|
@@ -20,57 +16,40 @@ class WatirModel
|
|
20
16
|
def inherited(subclass)
|
21
17
|
subclass.keys = keys.dup
|
22
18
|
subclass.defaults = defaults.dup
|
23
|
-
subclass.data_types = data_types.dup
|
24
|
-
end
|
25
|
-
|
26
|
-
%w(string float integer symbol time).each do |type|
|
27
|
-
define_method(type) do |symbol, &block|
|
28
|
-
key(symbol, &block)
|
29
|
-
data_types[symbol] = Object.const_get(type.capitalize)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def boolean(symbol, &block)
|
34
|
-
key(symbol, &block)
|
35
|
-
data_types[symbol] = 'Boolean'
|
36
19
|
end
|
37
20
|
|
38
21
|
# define a key and an optional block that provides a default value for the key
|
39
22
|
def key(symbol, &block)
|
40
23
|
keys << symbol unless @keys.include? symbol
|
41
24
|
attr_accessor symbol
|
42
|
-
data_types[symbol] = 'Key'
|
43
25
|
defaults[symbol] = block if block
|
44
26
|
end
|
27
|
+
|
28
|
+
def convert(hash, *args)
|
29
|
+
filtered = hash.reject { |k| !keys.include?(k) }
|
30
|
+
model = new(filtered)
|
31
|
+
args.each do |key|
|
32
|
+
model.instance_eval do
|
33
|
+
define_singleton_method(key) { hash[key] }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
model
|
37
|
+
end
|
45
38
|
end
|
46
39
|
|
47
|
-
def initialize(hash=
|
48
|
-
hash ||= {}
|
40
|
+
def initialize(hash={})
|
49
41
|
update(hash)
|
50
42
|
|
51
43
|
(self.class.defaults.keys - hash.keys).each do |key|
|
52
44
|
block = self.class.defaults[key]
|
53
|
-
|
54
|
-
result = ENV[key.to_s.upcase] || instance_exec(&block)
|
55
|
-
value = case
|
56
|
-
when object == 'Key'
|
57
|
-
result
|
58
|
-
when object == String
|
59
|
-
result.to_s
|
60
|
-
when object == Integer
|
61
|
-
result.to_i
|
62
|
-
when object == Float
|
63
|
-
result.to_f
|
64
|
-
when object == 'Boolean'
|
65
|
-
eval result
|
66
|
-
else
|
67
|
-
object.new result
|
68
|
-
end
|
45
|
+
value = default_value(key, block)
|
69
46
|
instance_variable_set("@#{key}", value)
|
70
47
|
end
|
71
48
|
end
|
72
49
|
|
73
50
|
def update(hash)
|
51
|
+
hash ||= {}
|
52
|
+
|
74
53
|
unknown = hash.keys - keys
|
75
54
|
if unknown.count > 0
|
76
55
|
raise ArgumentError, "unknown keyword#{'s' if unknown.count > 1}: #{unknown.join ', '}"
|
@@ -95,21 +74,14 @@ class WatirModel
|
|
95
74
|
opt ||= keys
|
96
75
|
opt.each_with_object({}) do |key, hash|
|
97
76
|
value = send(key)
|
98
|
-
|
77
|
+
next if value.nil?
|
78
|
+
hash[key] = value
|
99
79
|
end
|
100
80
|
end
|
101
81
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
when Hash
|
107
|
-
value.map { |k,v| [k, process_value(v)] }.to_h
|
108
|
-
when Array
|
109
|
-
value.map { |v| process_value(v) }
|
110
|
-
else
|
111
|
-
value
|
112
|
-
end
|
82
|
+
private
|
83
|
+
|
84
|
+
def default_value(key, block)
|
85
|
+
instance_exec(&block)
|
113
86
|
end
|
114
|
-
|
115
87
|
end
|
data/watir_model.gemspec
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Titus Fortner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,10 +75,12 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
|
+
- CHANGES.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|
83
|
+
- lib/config_model.rb
|
82
84
|
- lib/watir_model.rb
|
83
85
|
- watir_model.gemspec
|
84
86
|
homepage: https://github.com/titusfortner/watir_model
|