hydra_attribute 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ **0.4.1 (October 3, 2012)**
2
+ * Fixed bug which din't allow to use hydra attributes for STI models
3
+
1
4
  **0.4.0 (September 13, 2012)**
2
5
  * Add attribute sets
3
6
  * Add helper methods for attributes and attribute sets
data/README.md CHANGED
@@ -55,7 +55,7 @@ end
55
55
 
56
56
  ### Create model
57
57
  ```shell
58
- rails generate model Product type:string name:string --migration=false
58
+ rails generate model Product --migration=false
59
59
  rake db:migrate
60
60
  ```
61
61
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kostyantyn/Sites/github/gems/hydra_attribute
3
3
  specs:
4
- hydra_attribute (0.4.0.rc1)
4
+ hydra_attribute (0.4.1)
5
5
  activerecord (>= 3.1.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kostyantyn/Sites/github/gems/hydra_attribute
3
3
  specs:
4
- hydra_attribute (0.4.0.rc1)
4
+ hydra_attribute (0.4.1)
5
5
  activerecord (>= 3.1.0)
6
6
 
7
7
  GEM
@@ -14,22 +14,22 @@ module HydraAttribute
14
14
 
15
15
  module ClassMethods
16
16
  def hydra_attribute_methods_generated?
17
- @hydra_attribute_methods_generated ||= false
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
- @generated_hydra_attribute_methods ||= begin
22
- mod = Module.new
23
- include mod
24
- mod
25
- end
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
- @hydra_attribute_methods_mutex.synchronize do
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
- @hydra_attribute_methods_generated = true
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
- @hydra_attribute_methods_generated = false
73
+ base_class.instance_variable_set(:@hydra_attribute_methods_generated, false)
74
74
 
75
75
  clear_hydra_method_cache!
76
76
  end
@@ -1,3 +1,3 @@
1
1
  module HydraAttribute
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  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.0
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-09-12 00:00:00.000000000 Z
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: -1684889592311729317
225
+ hash: -3857802354378024215
226
226
  requirements: []
227
227
  rubyforge_project:
228
228
  rubygems_version: 1.8.24