watir_model 0.2.1 → 0.2.2

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: a67b953f8b1f5350855d9d42d3400ce4aa6087d0
4
- data.tar.gz: 27dca5010cdcb42b9fbdf767c2f794391ad97953
3
+ metadata.gz: 230ae59631b244a4ef743398ed5c3ee9df0a0c01
4
+ data.tar.gz: d639af104eae45b59bdbc304d4f5b84df9e1949c
5
5
  SHA512:
6
- metadata.gz: 7159633e30b9533c9cc6815f3f5c43b987b796231e098b77596da67f2f14143b4005abc54925146f47a225c8a4efce088e5f19db84ad94c63d08150831710352
7
- data.tar.gz: 17faf337effd568be3a9777ebbb5e12a6adbfe13b4c328a4126800cd9ce837850f3f36c114100f0ca6cec2b9391be0b48fd972148d3be2ac3a557fab734e1c4b
6
+ metadata.gz: 863596478876d2223aaf1047c070796e1d9e6905a6791fc4b7654d9e087b7794d1ca7f7ae35263a66fb736170e3d0aca274998583ec718da9d6aa6940a398ce7
7
+ data.tar.gz: aad2ad24e7c41e0cc5845180cc3dbde46c532f0b1242fb724ed78de52b4e143c78246eb3cabe6bc690930cfbde5e1ba3439d398538dd0e491f291f07cac788df
data/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2015 Bret Pettichord
4
+ Copyright (c) 2016 Titus Fortner
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
19
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
20
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
21
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
22
+ THE SOFTWARE.
data/lib/watir_model.rb CHANGED
@@ -3,12 +3,16 @@ require 'pp'
3
3
  class WatirModel
4
4
  class << self
5
5
 
6
- attr_writer :keys, :defaults
6
+ attr_writer :keys, :data_types, :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
+
12
16
  def defaults
13
17
  @defaults ||= {}
14
18
  end
@@ -16,12 +20,26 @@ class WatirModel
16
20
  def inherited(subclass)
17
21
  subclass.keys = keys.dup
18
22
  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'
19
36
  end
20
37
 
21
38
  # define a key and an optional block that provides a default value for the key
22
39
  def key(symbol, &block)
23
40
  keys << symbol unless @keys.include? symbol
24
41
  attr_accessor symbol
42
+ data_types[symbol] = 'Key'
25
43
  defaults[symbol] = block if block
26
44
  end
27
45
  end
@@ -32,16 +50,32 @@ class WatirModel
32
50
 
33
51
  (self.class.defaults.keys - hash.keys).each do |key|
34
52
  block = self.class.defaults[key]
35
- instance_variable_set("@#{key}", instance_exec(&block))
53
+ object = self.class.data_types[key]
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
69
+ instance_variable_set("@#{key}", value)
36
70
  end
37
71
  end
38
72
 
39
73
  def update(hash)
40
74
  unknown = hash.keys - keys
41
75
  if unknown.count > 0
42
- raise ArgumentError, "unknown keyword#{'s' if unknown.count > 1}: #{unknown.join', '}"
76
+ raise ArgumentError, "unknown keyword#{'s' if unknown.count > 1}: #{unknown.join ', '}"
43
77
  end
44
- hash.each {|key, v| instance_variable_set "@#{key}", v}
78
+ hash.each { |key, v| instance_variable_set "@#{key}", v }
45
79
  end
46
80
 
47
81
  def keys
data/watir_model.gemspec CHANGED
@@ -1,17 +1,14 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'watir_model/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "watir_model"
8
- spec.version = WatirModel::VERSION
9
- spec.authors = ["Bret Pettichord"]
10
- spec.email = ["bret@pettichord.com"]
5
+ spec.version = "0.2.2"
6
+ spec.authors = ["Titus Fortner"]
7
+ spec.email = ["titusfortner@gmail.com"]
11
8
 
12
9
  spec.summary = %q{This is a simple class for modelling test data.}
13
10
  spec.description = %q{This is a simple class for modelling test data. It is based on our experience with Watirmark::Model::Factory.}
14
- spec.homepage = "https://github.com/bret/watir_model"
11
+ spec.homepage = "https://github.com/titusfortner/watir_model"
15
12
  spec.license = "MIT"
16
13
 
17
14
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
- - Bret Pettichord
7
+ - Titus Fortner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,7 +69,7 @@ dependencies:
69
69
  description: This is a simple class for modelling test data. It is based on our experience
70
70
  with Watirmark::Model::Factory.
71
71
  email:
72
- - bret@pettichord.com
72
+ - titusfortner@gmail.com
73
73
  executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
@@ -80,9 +80,8 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - lib/watir_model.rb
83
- - lib/watir_model/version.rb
84
83
  - watir_model.gemspec
85
- homepage: https://github.com/bret/watir_model
84
+ homepage: https://github.com/titusfortner/watir_model
86
85
  licenses:
87
86
  - MIT
88
87
  metadata:
@@ -1,3 +0,0 @@
1
- class WatirModel
2
- VERSION = "0.2.1"
3
- end