active_fedora-registered_attributes 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,6 @@ require "active_fedora/registered_attributes/attribute_registry"
6
6
  module ActiveFedora
7
7
  module RegisteredAttributes
8
8
  extend ActiveSupport::Concern
9
- included do
10
- class_attribute :attribute_registry, instance_writer: false, instance_reader: false
11
- end
12
9
 
13
10
  delegate :attribute_defaults, to: :attribute_registry
14
11
  delegate :input_options_for, to: :attribute_registry
@@ -22,6 +19,17 @@ module ActiveFedora
22
19
  private :attribute_registry
23
20
 
24
21
  module ClassMethods
22
+ def attribute_registry
23
+ @attribute_registry ||=
24
+ begin
25
+ if superclass.respond_to?(:attribute_registry)
26
+ superclass.attribute_registry.copy_to(self)
27
+ else
28
+ AttributeRegistry.new(self)
29
+ end
30
+ end
31
+ end
32
+
25
33
  def registered_attribute_names
26
34
  attribute_registry.keys.collect(&:to_s)
27
35
  end
@@ -35,7 +43,6 @@ module ActiveFedora
35
43
  end
36
44
 
37
45
  def attribute(attribute_name, options ={})
38
- self.attribute_registry ||= AttributeRegistry.new(self)
39
46
  self.attribute_registry.register(attribute_name, options) do |attribute|
40
47
 
41
48
  attribute.with_validation_options do |name, opts|
@@ -7,9 +7,13 @@ module ActiveFedora
7
7
  module RegisteredAttributes
8
8
  class AttributeRegistry < DelegateClass(HashWithIndifferentAccess)
9
9
  attr_accessor :context_class
10
- def initialize(context_class)
10
+ def initialize(context_class, initial_container = HashWithIndifferentAccess.new)
11
11
  @context_class = context_class
12
- super(HashWithIndifferentAccess.new)
12
+ super(initial_container)
13
+ end
14
+
15
+ def copy_to(target)
16
+ self.class.new(target, __getobj__.dup)
13
17
  end
14
18
 
15
19
  def register(attribute_name, options)
@@ -1,5 +1,5 @@
1
1
  module ActiveFedora
2
2
  module RegisteredAttributes
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -75,6 +75,11 @@ describe 'ActiveFedora::RegisteredAttributes' do
75
75
  }
76
76
  }
77
77
  end
78
+
79
+ class ChildModel < MockDelegateAttribute
80
+ attribute :not_on_parent
81
+ end
82
+
78
83
  subject { MockDelegateAttribute.new() }
79
84
 
80
85
  describe '.registered_attribute_names' do
@@ -125,6 +130,29 @@ describe 'ActiveFedora::RegisteredAttributes' do
125
130
  end
126
131
 
127
132
  describe '.attribute' do
133
+
134
+ context 'for model inheritance' do
135
+ it 'does not add child declared attributes to parent class' do
136
+ expect {
137
+ MockDelegateAttribute.attribute_registry.fetch(:not_on_parent)
138
+ }.to raise_error(KeyError)
139
+ end
140
+
141
+ it 'children have parent attributes' do
142
+ expect {
143
+ ChildModel.attribute_registry.fetch(:title)
144
+ }.to_not raise_error(KeyError)
145
+ end
146
+
147
+ it 'children have attribute setting from parent' do
148
+ child = ChildModel.new
149
+
150
+ expect {
151
+ child.title = 'Hello'
152
+ }.to_not raise_error(NoMethodError)
153
+ end
154
+ end
155
+
128
156
  it 'handles attributes not delegated to a datastream' do
129
157
  subject.not_in_the_datastream = 'World?'
130
158
  expect(subject.not_in_the_datastream).to eq('World?')
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fedora-registered_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jeremy Friesen
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-29 00:00:00.000000000 Z
12
+ date: 2013-11-25 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: active-fedora
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 6.7.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 6.7.0
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: active_attr
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: bundler
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ~>
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
@@ -55,29 +62,33 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rake
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - '>='
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - '>='
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0'
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rspec
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - '>='
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: '0'
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - '>='
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: '0'
83
94
  description: An ActiveFedora extension for registring attributes
@@ -110,26 +121,33 @@ files:
110
121
  homepage: http://github.com/projecthydra/active_fedora-registered_attributes
111
122
  licenses:
112
123
  - APACHE2
113
- metadata: {}
114
124
  post_install_message:
115
125
  rdoc_options: []
116
126
  require_paths:
117
127
  - lib
118
128
  required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
119
130
  requirements:
120
- - - '>='
131
+ - - ! '>='
121
132
  - !ruby/object:Gem::Version
122
133
  version: '0'
134
+ segments:
135
+ - 0
136
+ hash: 136137362571869666
123
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
124
139
  requirements:
125
- - - '>='
140
+ - - ! '>='
126
141
  - !ruby/object:Gem::Version
127
142
  version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 136137362571869666
128
146
  requirements: []
129
147
  rubyforge_project:
130
- rubygems_version: 2.0.3
148
+ rubygems_version: 1.8.25
131
149
  signing_key:
132
- specification_version: 4
150
+ specification_version: 3
133
151
  summary: An ActiveFedora extension for registring attributes
134
152
  test_files:
135
153
  - spec/lib/active_fedora/registered_attributes/attribute_registry_spec.rb
@@ -137,4 +155,3 @@ test_files:
137
155
  - spec/lib/active_fedora/registered_attributes_spec.rb
138
156
  - spec/spec_helper.rb
139
157
  - spec/support/book.rb
140
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 4dc9320ae00b5cf5bb2128d3d6174300ea078e14
4
- data.tar.gz: 669c91334c14819d2c81d2bca307330f9d225b7f
5
- SHA512:
6
- metadata.gz: 2abaf01c420893621250fc64e6f2de6b8dad920611c72ed17824ccb64821689a6c907371602fc486075e2afd900cb37122176c468380985dff90bc6dd3157889
7
- data.tar.gz: 72631225b897f31797a2c1cb3abf1084a473e318a47d6ed79f0bd0bb67f341a3ccd70da18fac29ee8084b918fdd9ac9ec358354e9fc06cc3b01cbc4528fa0ff0