acfs 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/acfs/resource/attributes.rb +10 -36
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/resource/attributes_spec.rb +15 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a815614c14477b727317758c4deb950750c1609
|
4
|
+
data.tar.gz: d1413e76db34215713693cf20b88e6d2e751efe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 775cf10dd61a350c67faab9704685f251f0e7416cc2c9055b6373be1f6a7419c130e914ad2897b2f79aa5781eec02e8bc7054cbe91078ff8773a57965297604e
|
7
|
+
data.tar.gz: 3d6f4f31d2573375cad139c75a7f24131037b0211cc28bb6143709a391f4ab542357bb7c51fa4984788e739797fdf9c68e22fc58b1d61669173c0d85b0402ce8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.48.0
|
4
|
+
|
5
|
+
* Remove #attribute_types broke since f7e4109 (Sep 2013, v0.23)
|
6
|
+
* Fix attribute inheritance on subclassing broken since commit 7cf1d11 (Apr 2014, v0.43)
|
7
|
+
|
3
8
|
## 0.47.0
|
4
9
|
|
5
10
|
* Change blank value handling of dict and list type (0a12ef1)
|
@@ -222,56 +222,30 @@ class Acfs::Resource
|
|
222
222
|
# Attributes with default values.
|
223
223
|
#
|
224
224
|
def attributes
|
225
|
-
{}
|
226
|
-
|
227
|
-
attrs[key] = attr.default_value
|
228
|
-
end
|
225
|
+
defined_attributes.each_with_object({}) do |(key, attr), hash|
|
226
|
+
hash[key] = attr.default_value
|
229
227
|
end
|
230
228
|
end
|
231
229
|
|
232
230
|
def defined_attributes
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
attributes
|
231
|
+
if superclass.respond_to?(:defined_attributes)
|
232
|
+
superclass.defined_attributes.merge(local_attributes)
|
233
|
+
else
|
234
|
+
local_attributes
|
240
235
|
end
|
241
236
|
end
|
242
237
|
|
243
|
-
|
244
|
-
#
|
245
|
-
# Return hash of attributes and there types.
|
246
|
-
#
|
247
|
-
# @example
|
248
|
-
# class User < Acfs::Resource
|
249
|
-
# attribute :name, :string
|
250
|
-
# attribute :age, :integer, default: 25
|
251
|
-
# end
|
252
|
-
# User.attributes # => {"name": Acfs::Model::Attributes::String,
|
253
|
-
# # "age": Acfs::Model::Attributes::Integer}
|
254
|
-
#
|
255
|
-
# @return [Hash{Symbol => Class}] Attributes and their types.
|
256
|
-
#
|
257
|
-
def attribute_types
|
258
|
-
@attribute_types ||= begin
|
259
|
-
attribute_types = {}
|
260
|
-
if superclass.respond_to?(:attribute_types)
|
261
|
-
attribute_types.merge superclass.attribute_types
|
262
|
-
end
|
238
|
+
private
|
263
239
|
|
264
|
-
|
265
|
-
|
240
|
+
def local_attributes
|
241
|
+
@local_attributes ||= {}
|
266
242
|
end
|
267
243
|
|
268
|
-
private
|
269
|
-
|
270
244
|
def define_attribute(name, type, opts = {})
|
271
245
|
name = name.to_s
|
272
246
|
attribute = type.new opts
|
273
247
|
|
274
|
-
|
248
|
+
local_attributes[name] = attribute
|
275
249
|
define_attribute_method name
|
276
250
|
|
277
251
|
send :define_method, name do
|
data/lib/acfs/version.rb
CHANGED
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes do
|
4
4
|
let(:model) { Class.new Acfs::Resource }
|
5
|
+
let(:submodel) { Class.new model }
|
5
6
|
|
6
7
|
describe '#initialize' do
|
7
8
|
before { model.attribute :name, :string, default: 'John' }
|
@@ -137,7 +138,7 @@ describe Acfs::Resource::Attributes do
|
|
137
138
|
end
|
138
139
|
|
139
140
|
describe 'class' do
|
140
|
-
describe '#
|
141
|
+
describe '#attributes' do
|
141
142
|
it 'should add an attribute to model attribute list' do
|
142
143
|
model.send :attribute, :name, :string
|
143
144
|
|
@@ -150,18 +151,29 @@ describe Acfs::Resource::Attributes do
|
|
150
151
|
expect(model.attributes.symbolize_keys).to eq name: 'John'
|
151
152
|
end
|
152
153
|
|
153
|
-
it 'should accept
|
154
|
+
it 'should accept a symbolic type' do
|
154
155
|
model.send :attribute, :age, :integer, default: '12'
|
155
156
|
|
156
157
|
expect(model.attributes.symbolize_keys).to eq age: 12
|
157
158
|
end
|
158
159
|
|
159
|
-
it 'should accept
|
160
|
+
it 'should accept a class type' do
|
160
161
|
model.send :attribute, :age, Acfs::Resource::Attributes::Integer,
|
161
162
|
default: '12'
|
162
163
|
|
163
164
|
expect(model.attributes.symbolize_keys).to eq age: 12
|
164
165
|
end
|
166
|
+
|
167
|
+
context 'on inherited resources' do
|
168
|
+
before do
|
169
|
+
model.attribute :age, :integer, default: 5
|
170
|
+
submodel.attribute :born_at, :date_time
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'includes superclass attributes' do
|
174
|
+
expect(submodel.attributes.keys).to match_array %w(age born_at)
|
175
|
+
end
|
176
|
+
end
|
165
177
|
end
|
166
178
|
end
|
167
179
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.48.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|