has_inherited 1.0.0 → 2.0.0
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/README.rdoc +1 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/has_inherited.gemspec +14 -21
- data/lib/has_inherited.rb +3 -3
- data/spec/has_inherited_spec.rb +10 -3
- metadata +11 -12
- data/.gitignore +0 -22
data/README.rdoc
CHANGED
@@ -8,6 +8,7 @@ Easily share variables between Rails models with inheritance.
|
|
8
8
|
|
9
9
|
== Using has_inheritable
|
10
10
|
|
11
|
+
(*NOTE*: has_inherited 2.x or greater only works with Rails 3. If you need Rails 2.x support please use has_inherited 1.0)
|
11
12
|
The intention of this library is to make it easy to inherit particular variables between models in rails apps. We start with a parent model that will function as a pseudo-polymorphic association for children objects.
|
12
13
|
|
13
14
|
=== 1. Define a parent object
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.description = "The intention of this library is to make it easy to inherit particular variables between models in rails apps. We start with a parent model that will function as a pseudo-polymorphic association for children objects."
|
10
10
|
gem.email = "mark@amerine.net"
|
11
11
|
gem.homepage = "http://github.com/amerine/has_inherited"
|
12
|
-
gem.authors = ["Mark Turner"]
|
12
|
+
gem.authors = ["Mark Turner", "Steve Burkett"]
|
13
13
|
gem.add_development_dependency "bacon", ">= 0"
|
14
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
15
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/has_inherited.gemspec
CHANGED
@@ -1,45 +1,38 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{has_inherited}
|
8
|
-
s.version = "
|
8
|
+
s.version = "2.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Mark Turner"]
|
12
|
-
s.date = %q{
|
11
|
+
s.authors = ["Mark Turner", "Steve Burkett"]
|
12
|
+
s.date = %q{2011-05-02}
|
13
13
|
s.description = %q{The intention of this library is to make it easy to inherit particular variables between models in rails apps. We start with a parent model that will function as a pseudo-polymorphic association for children objects.}
|
14
14
|
s.email = %q{mark@amerine.net}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
"spec/spec_helper.rb"
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"has_inherited.gemspec",
|
26
|
+
"lib/has_inherited.rb",
|
27
|
+
"spec/has_inherited_spec.rb",
|
28
|
+
"spec/spec_helper.rb"
|
30
29
|
]
|
31
30
|
s.homepage = %q{http://github.com/amerine/has_inherited}
|
32
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
33
31
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.
|
32
|
+
s.rubygems_version = %q{1.6.2}
|
35
33
|
s.summary = %q{Easily share variables between Rails models with inheritance.}
|
36
|
-
s.test_files = [
|
37
|
-
"spec/has_inherited_spec.rb",
|
38
|
-
"spec/spec_helper.rb"
|
39
|
-
]
|
40
34
|
|
41
35
|
if s.respond_to? :specification_version then
|
42
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
36
|
s.specification_version = 3
|
44
37
|
|
45
38
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/has_inherited.rb
CHANGED
@@ -8,7 +8,7 @@ module HasInherited
|
|
8
8
|
attr = name.shift || :global
|
9
9
|
assoc = "_#{attr}"
|
10
10
|
|
11
|
-
|
11
|
+
scope assoc.to_sym,
|
12
12
|
:conditions => 'inheritable_id IS NULL AND inheritable_type IS NULL'
|
13
13
|
|
14
14
|
(class << self; self; end).instance_eval do
|
@@ -30,7 +30,7 @@ module HasInherited
|
|
30
30
|
has_many assoc.to_sym, :class_name => class_name, :as => :inheritable, :dependent => :destroy
|
31
31
|
|
32
32
|
define_method attr do
|
33
|
-
|
33
|
+
instance_variable_get(:"@#{attr.to_s}") || instance_variable_set(:"@#{attr.to_s}", InheritAccessor.new(self, assoc.to_sym, options[:from]))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end # ClassMethods
|
@@ -86,7 +86,7 @@ module HasInherited
|
|
86
86
|
|
87
87
|
def all(inherited = true)
|
88
88
|
all_values = {}
|
89
|
-
@assoc.all.each {|
|
89
|
+
@assoc.all.each {|ina| all_values[ina.name.to_sym] = ina.value}
|
90
90
|
if inherited
|
91
91
|
parent_proxy = parent
|
92
92
|
while parent_proxy
|
data/spec/has_inherited_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'logger'
|
2
3
|
|
3
4
|
|
4
5
|
class Seo < ActiveRecord::Base
|
@@ -38,18 +39,18 @@ describe "HasInherited" do
|
|
38
39
|
end
|
39
40
|
|
40
41
|
create_table :industries do |t|
|
41
|
-
t.
|
42
|
+
t.string :name
|
42
43
|
t.timestamps
|
43
44
|
end
|
44
45
|
|
45
46
|
create_table :clients do |t|
|
46
|
-
t.
|
47
|
+
t.string :name
|
47
48
|
t.references :industry
|
48
49
|
t.timestamps
|
49
50
|
end
|
50
51
|
|
51
52
|
create_table :stores do |t|
|
52
|
-
t.
|
53
|
+
t.string :name
|
53
54
|
t.references :client
|
54
55
|
t.timestamps
|
55
56
|
end
|
@@ -81,6 +82,12 @@ describe "HasInherited" do
|
|
81
82
|
industry.seo.title.should.equal "Title"
|
82
83
|
end
|
83
84
|
|
85
|
+
it "should be able to grab all the global values" do
|
86
|
+
Seo.global.title = "Global Title"
|
87
|
+
Seo.global.foo = "Global Foo"
|
88
|
+
Seo.global.all.size.should.equal 2
|
89
|
+
end
|
90
|
+
|
84
91
|
it "should work with two levels of nesting" do
|
85
92
|
Seo.global.title = "SEO Title"
|
86
93
|
industry = Industry.create
|
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_inherited
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
version:
|
10
|
+
version: 2.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mark Turner
|
14
|
+
- Steve Burkett
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date:
|
19
|
+
date: 2011-05-02 00:00:00 -07:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +44,6 @@ extra_rdoc_files:
|
|
43
44
|
- README.rdoc
|
44
45
|
files:
|
45
46
|
- .document
|
46
|
-
- .gitignore
|
47
47
|
- LICENSE
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
@@ -57,8 +57,8 @@ homepage: http://github.com/amerine/has_inherited
|
|
57
57
|
licenses: []
|
58
58
|
|
59
59
|
post_install_message:
|
60
|
-
rdoc_options:
|
61
|
-
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
62
|
require_paths:
|
63
63
|
- lib
|
64
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -82,10 +82,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
requirements: []
|
83
83
|
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.
|
85
|
+
rubygems_version: 1.6.2
|
86
86
|
signing_key:
|
87
87
|
specification_version: 3
|
88
88
|
summary: Easily share variables between Rails models with inheritance.
|
89
|
-
test_files:
|
90
|
-
|
91
|
-
- spec/spec_helper.rb
|
89
|
+
test_files: []
|
90
|
+
|