acfs 0.47.0 → 0.48.0

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: decb9d3e9d395a8be85fbe1121af69d5d14760dc
4
- data.tar.gz: a9a4ec3bfd5181238ff1075c1f2c201193e4c6c7
3
+ metadata.gz: 0a815614c14477b727317758c4deb950750c1609
4
+ data.tar.gz: d1413e76db34215713693cf20b88e6d2e751efe3
5
5
  SHA512:
6
- metadata.gz: 9e32e66070e87b77c91d6046b378896aaaf76a45bdaae3a08b9fd00264b5e5bef80003b04de602abffba08fcf3e8892673025659636ff753679c9ee3104e5ded
7
- data.tar.gz: a2c3cf04e5f8edc101c9af0d5c8afc6c24d5990ccbc8c36025c99fea69a13e6bc426269c8b2de7b95f57644563ded48b1446d18e721afbd36da786515b7b1fda
6
+ metadata.gz: 775cf10dd61a350c67faab9704685f251f0e7416cc2c9055b6373be1f6a7419c130e914ad2897b2f79aa5781eec02e8bc7054cbe91078ff8773a57965297604e
7
+ data.tar.gz: 3d6f4f31d2573375cad139c75a7f24131037b0211cc28bb6143709a391f4ab542357bb7c51fa4984788e739797fdf9c68e22fc58b1d61669173c0d85b0402ce8
@@ -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
- {}.tap do |attrs|
226
- defined_attributes.each do |key, attr|
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
- @attributes ||= begin
234
- attributes = {}
235
- if superclass.respond_to?(:defined_attributes)
236
- attributes.merge superclass.defined_attributes
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
- # @api public
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
- attribute_types
265
- end
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
- defined_attributes[name] = attribute
248
+ local_attributes[name] = attribute
275
249
  define_attribute_method name
276
250
 
277
251
  send :define_method, name do
@@ -1,7 +1,7 @@
1
1
  module Acfs
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 47
4
+ MINOR = 48
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
 
@@ -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 '#attribute' do
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 an symbolic type' do
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 an class type' do
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.47.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-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport