hydra_attribute 0.4.0 → 0.4.1
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.
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/gemfiles/3.1.gemfile.lock +1 -1
- data/gemfiles/3.2.gemfile.lock +1 -1
- data/lib/hydra_attribute/active_record/attribute_methods.rb +9 -9
- data/lib/hydra_attribute/version.rb +1 -1
- data/spec/hydra_attribute/active_record/attribute_methods_spec.rb +22 -0
- metadata +3 -3
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/gemfiles/3.1.gemfile.lock
CHANGED
data/gemfiles/3.2.gemfile.lock
CHANGED
@@ -14,22 +14,22 @@ module HydraAttribute
|
|
14
14
|
|
15
15
|
module ClassMethods
|
16
16
|
def hydra_attribute_methods_generated?
|
17
|
-
|
17
|
+
base_class.instance_variable_get(:@hydra_attribute_methods_generated) || base_class.instance_variable_set(:@hydra_attribute_methods_generated, false)
|
18
18
|
end
|
19
19
|
|
20
20
|
def generated_hydra_attribute_methods
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
return base_class.instance_variable_get(:@generated_hydra_attribute_methods) if base_class.instance_variable_defined?(:@generated_hydra_attribute_methods)
|
22
|
+
|
23
|
+
mod = Module.new
|
24
|
+
base_class.send(:include, mod)
|
25
|
+
base_class.instance_variable_set(:@generated_hydra_attribute_methods, mod)
|
26
26
|
end
|
27
27
|
|
28
28
|
def define_hydra_attribute_methods
|
29
|
-
|
29
|
+
base_class.instance_variable_get(:@hydra_attribute_methods_mutex).synchronize do
|
30
30
|
return if hydra_attribute_methods_generated?
|
31
31
|
hydra_attributes.each { |hydra_attribute| define_hydra_attribute_method(hydra_attribute) }
|
32
|
-
|
32
|
+
base_class.instance_variable_set(:@hydra_attribute_methods_generated, true)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -70,7 +70,7 @@ module HydraAttribute
|
|
70
70
|
generated_hydra_attribute_methods.module_eval do
|
71
71
|
instance_methods.each { |m| undef_method(m) }
|
72
72
|
end
|
73
|
-
|
73
|
+
base_class.instance_variable_set(:@hydra_attribute_methods_generated, false)
|
74
74
|
|
75
75
|
clear_hydra_method_cache!
|
76
76
|
end
|
@@ -12,6 +12,28 @@ describe HydraAttribute::ActiveRecord::AttributeMethods do
|
|
12
12
|
product.color
|
13
13
|
end.should raise_error(HydraAttribute::MissingAttributeInHydraSetError, %(Hydra attribute "color" does not exist in hydra set "Default"))
|
14
14
|
end
|
15
|
+
|
16
|
+
it 'should not throw error when new sub class instance is created' do
|
17
|
+
Product.hydra_attributes.create(name: 'color', backend_type: 'string')
|
18
|
+
Product.reset_hydra_attribute_methods!
|
19
|
+
|
20
|
+
sub_class = Class.new(Product)
|
21
|
+
lambda do
|
22
|
+
sub_class.new.color
|
23
|
+
end.should_not raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should allow access to attributes from base model and its sub model' do
|
27
|
+
Product.hydra_attributes.create(name: 'color', backend_type: 'string')
|
28
|
+
Product.reset_hydra_attribute_methods!
|
29
|
+
Product.send(:remove_instance_variable, :@generated_hydra_attribute_methods)
|
30
|
+
|
31
|
+
sub_class = Class.new(Product)
|
32
|
+
lambda do
|
33
|
+
sub_class.new.color
|
34
|
+
Product.new.color
|
35
|
+
end.should_not raise_error
|
36
|
+
end
|
15
37
|
end
|
16
38
|
end
|
17
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
version: '0'
|
223
223
|
segments:
|
224
224
|
- 0
|
225
|
-
hash: -
|
225
|
+
hash: -3857802354378024215
|
226
226
|
requirements: []
|
227
227
|
rubyforge_project:
|
228
228
|
rubygems_version: 1.8.24
|