thin_models 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 621ce5c7fe4ce985ba4d945e44e6743e8edfe882
4
+ data.tar.gz: 79871034c85bed45dff1dd2da0f3d70aa3e72d7f
5
+ SHA512:
6
+ metadata.gz: cc9d607fff902266168f8799caf2b9ca159dfe7bb4e0824097e2f8446a4334e412bc8cd70693090b3108d4c7fa86a9a8249b004441716ba00492f11cb1bc47fe
7
+ data.tar.gz: eb713382a79a91ac159ac3fcb974875b2da67420bccc231dd7cdf6f5ecff16f9e6efd03959491fc1181d976f75fef21b402a311dc2aed137d22a58460da1b481
@@ -9,15 +9,21 @@ module ThinModels
9
9
  end
10
10
 
11
11
  def initialize(values=nil, skip_checks=false, &lazy_values)
12
- @values = values || {}
12
+ @values = (values || {}).reduce({}) { |m, (k, v)| m[k.to_sym] = v; m }
13
13
  @lazy_values = lazy_values if lazy_values
14
14
  check_attributes if values && !skip_checks
15
15
  end
16
16
 
17
17
  def check_attributes
18
- attributes = self.class.attributes
19
18
  @values.each_key do |attribute|
20
- raise NameError, "no attribute #{attribute} in #{self.class}" unless attributes.include?(attribute)
19
+ check_attribute(attribute)
20
+ end
21
+ end
22
+
23
+ def check_attribute(attribute)
24
+ attributes = self.class.attributes.map(&:to_s)
25
+ unless attributes.include?(attribute.to_s)
26
+ fail NameError, "no attribute #{attribute} in #{self.class}"
21
27
  end
22
28
  end
23
29
 
@@ -67,10 +73,11 @@ module ThinModels
67
73
  alias :keys :loaded_attributes
68
74
 
69
75
  def [](attribute)
70
- if @values.has_key?(attribute)
71
- @values[attribute]
76
+ check_attribute(attribute)
77
+ attribute = attribute.to_sym
78
+ if @values.has_key?(attribute.to_sym)
79
+ @values[attribute.to_sym]
72
80
  else
73
- raise NameError, "no attribute #{attribute} in #{self.class}" unless self.class.attributes.include?(attribute)
74
81
  if @lazy_values
75
82
  @values[attribute] = @lazy_values.call(self, attribute)
76
83
  end
@@ -78,10 +85,11 @@ module ThinModels
78
85
  end
79
86
 
80
87
  def fetch(attribute)
88
+ check_attribute(attribute)
89
+ attribute = attribute.to_sym
81
90
  if @values.has_key?(attribute)
82
91
  @values[attribute]
83
92
  else
84
- raise NameError, "no attribute #{attribute} in #{self.class}" unless self.class.attributes.include?(attribute)
85
93
  if @lazy_values
86
94
  @values[attribute] = @lazy_values.call(self, attribute)
87
95
  else
@@ -91,7 +99,8 @@ module ThinModels
91
99
  end
92
100
 
93
101
  def []=(attribute, value)
94
- raise NameError, "no attribute #{attribute.inspect} in #{self.class}" unless self.class.attributes.include?(attribute)
102
+ check_attribute(attribute)
103
+ attribute = attribute.to_sym
95
104
  @values[attribute] = value
96
105
  end
97
106
 
@@ -101,7 +110,7 @@ module ThinModels
101
110
 
102
111
  def merge!(updated_values)
103
112
  updated_values.to_hash.each_key do |attribute|
104
- raise NameError, "no attribute #{attribute.inspect} in #{self.class}" unless attributes.include?(attribute)
113
+ check_attribute(attribute)
105
114
  end
106
115
  @values.merge!(updated_values)
107
116
  self
@@ -1,3 +1,3 @@
1
1
  module ThinModels
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thin_models
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
4
+ version: 0.2.0
11
5
  platform: ruby
12
6
  authors:
13
7
  - Matthew Willson
@@ -15,77 +9,42 @@ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
11
 
18
- date: 2011-11-12 00:00:00 Z
12
+ date: 2015-03-03 00:00:00 Z
19
13
  dependencies:
20
14
  - !ruby/object:Gem::Dependency
21
15
  name: rake
22
16
  prerelease: false
23
17
  requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
18
  requirements:
26
- - - ">="
19
+ - &id002
20
+ - ">="
27
21
  - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
22
  version: "0"
32
23
  type: :development
33
24
  version_requirements: *id001
34
25
  - !ruby/object:Gem::Dependency
35
26
  name: test-spec
36
27
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
46
- type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: mocha
50
- prerelease: false
51
28
  requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
29
  requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
30
+ - *id002
60
31
  type: :development
61
32
  version_requirements: *id003
62
33
  - !ruby/object:Gem::Dependency
63
- name: autotest
34
+ name: mocha
64
35
  prerelease: false
65
36
  requirement: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
37
  requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
38
+ - *id002
74
39
  type: :development
75
40
  version_requirements: *id004
76
41
  - !ruby/object:Gem::Dependency
77
42
  name: typisch
78
43
  prerelease: false
79
44
  requirement: &id005 !ruby/object:Gem::Requirement
80
- none: false
81
45
  requirements:
82
46
  - - ~>
83
47
  - !ruby/object:Gem::Version
84
- hash: 19
85
- segments:
86
- - 0
87
- - 1
88
- - 4
89
48
  version: 0.1.4
90
49
  type: :development
91
50
  version_requirements: *id005
@@ -99,46 +58,36 @@ extensions: []
99
58
  extra_rdoc_files: []
100
59
 
101
60
  files:
61
+ - README.txt
102
62
  - lib/thin_models.rb
103
- - lib/thin_models/version.rb
63
+ - lib/thin_models/errors.rb
64
+ - lib/thin_models/lazy_array.rb
104
65
  - lib/thin_models/struct.rb
105
- - lib/thin_models/struct/typed.rb
106
66
  - lib/thin_models/struct/identity.rb
107
- - lib/thin_models/lazy_array.rb
108
- - lib/thin_models/errors.rb
109
- - README.txt
67
+ - lib/thin_models/struct/typed.rb
68
+ - lib/thin_models/version.rb
110
69
  homepage:
111
70
  licenses: []
112
71
 
72
+ metadata: {}
73
+
113
74
  post_install_message:
114
75
  rdoc_options: []
115
76
 
116
77
  require_paths:
117
78
  - lib
118
79
  required_ruby_version: !ruby/object:Gem::Requirement
119
- none: false
120
80
  requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
- version: "0"
81
+ - *id002
127
82
  required_rubygems_version: !ruby/object:Gem::Requirement
128
- none: false
129
83
  requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
134
- - 0
135
- version: "0"
84
+ - *id002
136
85
  requirements: []
137
86
 
138
87
  rubyforge_project:
139
- rubygems_version: 1.8.10
88
+ rubygems_version: 2.4.6
140
89
  signing_key:
141
- specification_version: 3
90
+ specification_version: 4
142
91
  summary: Some convenience classes for 'thin models' -- pure domain model data objects which are devoid of persistence and other infrastructural concerns
143
92
  test_files: []
144
93