property_sets 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/property_sets.rb CHANGED
@@ -8,8 +8,8 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  module PropertySets
11
- def self.ensure_property_set_class(association, owner_class)
12
- const_name = "#{owner_class.name}#{association.to_s.singularize.capitalize}".to_sym
11
+ def self.ensure_property_set_class(association, owner_class_name)
12
+ const_name = "#{owner_class_name}#{association.to_s.singularize.capitalize}".to_sym
13
13
  unless Object.const_defined?(const_name)
14
14
  property_class = Object.const_set(const_name, Class.new(ActiveRecord::Base))
15
15
  property_class.class_eval do
@@ -17,7 +17,7 @@ module PropertySets
17
17
  extend PropertySets::PropertySetModel::ClassMethods
18
18
  end
19
19
 
20
- property_class.owner_class = owner_class
20
+ property_class.owner_class = owner_class_name
21
21
  property_class.owner_assoc = association
22
22
  end
23
23
  Object.const_get(const_name)
@@ -15,7 +15,10 @@ module PropertySets
15
15
  raise "Invalid association name, letters only" unless association.to_s =~ /[a-z]+/
16
16
  self.property_set_index << association
17
17
 
18
- property_class = PropertySets.ensure_property_set_class(association, self)
18
+ property_class = PropertySets.ensure_property_set_class(
19
+ association,
20
+ options.delete(:owner_class_name) || self.name
21
+ )
19
22
  property_class.instance_eval(&block)
20
23
 
21
24
  hash_opts = {:class_name => property_class.name, :autosave => true, :dependent => :destroy}.merge(options)
@@ -120,8 +120,8 @@ module PropertySets
120
120
  @properties[key] && !!@properties[key][:protected]
121
121
  end
122
122
 
123
- def owner_class=(owner_class)
124
- @owner_class_sym = owner_class.name.underscore.to_sym
123
+ def owner_class=(owner_class_name)
124
+ @owner_class_sym = owner_class_name.underscore.to_sym
125
125
  belongs_to owner_class_sym
126
126
  validates_presence_of owner_class_sym
127
127
  validates_uniqueness_of :name, :scope => owner_class_key_sym
@@ -1,3 +1,3 @@
1
1
  module PropertySets
2
- VERSION = "2.2.1"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -20,6 +20,14 @@ class TestPropertySets < ActiveSupport::TestCase
20
20
  end
21
21
  end
22
22
 
23
+ should "allow the owner class to be customized" do
24
+ (Flux = Class.new(ActiveRecord::Base)).property_set(:blot, {
25
+ :owner_class_name => 'Foobar'
26
+ }) { property :test }
27
+
28
+ assert defined?(FoobarBlot)
29
+ end
30
+
23
31
  should "pass-through any options from the second parameter" do
24
32
  Account.expects(:has_many).with { |association, h|
25
33
  association == :foo && h[:conditions] == "bar"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property_sets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
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: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -131,3 +131,4 @@ signing_key:
131
131
  specification_version: 3
132
132
  summary: Property sets for ActiveRecord.
133
133
  test_files: []
134
+ has_rdoc: