classy 1.0.2 → 1.0.3
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 +4 -3
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/classy/aliasable.rb +2 -2
- data/lib/classy/subclass_aware.rb +26 -14
- data/spec/spec.opts +1 -1
- data/spec/templatable_spec.rb +0 -0
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= classy
|
2
2
|
|
3
|
-
Classy is a collection of
|
4
|
-
|
3
|
+
Classy is a collection of metaprogramming-heavy modules which you can extend in
|
4
|
+
order to give various capabilities to your Ruby classes. For example,
|
5
5
|
SubclassAware lets a class know about all of its subclasses (and
|
6
6
|
sub-subclasses, etc), and Aliasable lets you refer to classes via symbols
|
7
7
|
(useful for creating friendly DSLs).
|
@@ -27,7 +27,8 @@ sub-subclasses, etc), and Aliasable lets you refer to classes via symbols
|
|
27
27
|
Parent.subclasses # => [ ChildA, ChildB ]
|
28
28
|
|
29
29
|
More extensive documentation and example code can be found in the RDoc for each
|
30
|
-
module
|
30
|
+
module (available online at http://rdoc.info/projects/djspinmonkey/classy) or
|
31
|
+
in the spec files.
|
31
32
|
|
32
33
|
== Note on Patches/Pull Requests
|
33
34
|
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "classy"
|
8
8
|
gem.summary = %Q{A collection of modules to enhance the capabilities of Ruby classes in various ways.}
|
9
|
-
gem.description = %Q{Classy is a collection of
|
9
|
+
gem.description = %Q{Classy is a collection of metaprogramming-heavy modules which you can extend in order to give various capabilities to your Ruby classes. For example, SubclassAware lets a class know about all of its subclasses (and sub-subclasses, etc), and Aliasable lets you refer to classes via symbols (useful for creating friendly DSLs).}
|
10
10
|
gem.email = "github@djspinmonkey.com"
|
11
11
|
gem.homepage = "http://github.com/djspinmonkey/classy"
|
12
12
|
gem.authors = ["John Hyland"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/lib/classy/aliasable.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Aliasable allows you to assign aliases to a class (
|
1
|
+
# Aliasable allows you to assign aliases to a class (usually symbols, but any
|
2
2
|
# unique objects would work) and look it up again later with that alias. This
|
3
3
|
# alias-to-class hash is kept in a class variable, so each mapping is unique to
|
4
4
|
# a given class hierarchy. Possible uses for this include friendlier DSLs or
|
@@ -11,7 +11,7 @@
|
|
11
11
|
# maps as a class variable on the Aliasable module itself, but for reasons of
|
12
12
|
# complexity and performance, that has not been done at this time.
|
13
13
|
#
|
14
|
-
# Example
|
14
|
+
# ==Example
|
15
15
|
#
|
16
16
|
# class ParentClass
|
17
17
|
# extend Aliasable
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'set'
|
2
2
|
|
3
3
|
# SubclassAware allows a class to know about all of the subclasses that descend
|
4
|
-
# from it in the inheritance tree.
|
4
|
+
# from it in the inheritance tree.
|
5
5
|
#
|
6
|
-
# Example
|
6
|
+
# == Example
|
7
7
|
#
|
8
8
|
# class Parent
|
9
9
|
# extend SubclassAware
|
@@ -20,11 +20,18 @@ require 'set'
|
|
20
20
|
#
|
21
21
|
# Parent.subclasses # => [ ChildA, ChildB, ChildB1 ]
|
22
22
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
23
|
+
# == Note
|
24
|
+
#
|
25
|
+
# SubclassAware sets and maintains the class variable @@classy_subclasses on
|
26
|
+
# the extending class, so in the unlikely event that this class variable is
|
27
|
+
# already in use, unusual bugs may result.
|
28
|
+
#
|
29
|
+
# == Warning
|
30
|
+
#
|
31
|
+
# This module defines an inherited() class method on the extending class to
|
32
|
+
# keep track of subclasses. Unfortunately, if this method is later re-defined,
|
33
|
+
# this inherited() method is lost and subclass tracking will break. In order
|
34
|
+
# to work around this, constructions like the following might be necessary:
|
28
35
|
#
|
29
36
|
# class ChildC < Parent
|
30
37
|
#
|
@@ -41,30 +48,35 @@ require 'set'
|
|
41
48
|
#
|
42
49
|
module SubclassAware
|
43
50
|
|
44
|
-
|
45
|
-
|
51
|
+
# Instantiate a new Set of subclasses. Not intended to be called directly.
|
52
|
+
#
|
53
|
+
def self.extended(klass)
|
54
|
+
klass.class_exec { class_variable_set(:@@classy_subclasses, Set.new) }
|
46
55
|
end
|
47
56
|
|
57
|
+
# Add the inheriting class to the list of subclasses. Not intended to be
|
58
|
+
# called directly.
|
59
|
+
#
|
48
60
|
# TODO: Find a way for self.inherited on the extended class not to blow
|
49
61
|
# this away without requiring a bunch of alias chain hoops to be jumped
|
50
|
-
# through.
|
62
|
+
# through, as described above.
|
51
63
|
#
|
52
|
-
def inherited(sub)
|
53
|
-
class_exec { class_variable_get(:@@
|
64
|
+
def inherited(sub)
|
65
|
+
class_exec { class_variable_get(:@@classy_subclasses).add sub }
|
54
66
|
end
|
55
67
|
|
56
68
|
# Return an array of all known subclasses (and sub-subclasses, etc) of this
|
57
69
|
# class.
|
58
70
|
#
|
59
71
|
def subclasses
|
60
|
-
class_exec { class_variable_get(:@@
|
72
|
+
class_exec { class_variable_get(:@@classy_subclasses).to_a }
|
61
73
|
end
|
62
74
|
|
63
75
|
# Clear all info about known subclasses. This method is probably mainly
|
64
76
|
# useful for testing.
|
65
77
|
#
|
66
78
|
def forget_subclasses
|
67
|
-
class_exec { class_variable_get(:@@
|
79
|
+
class_exec { class_variable_get(:@@classy_subclasses).clear }
|
68
80
|
end
|
69
81
|
|
70
82
|
end
|
data/spec/spec.opts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color
|
1
|
+
-fn --color
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hyland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-04 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.2.9
|
24
24
|
version:
|
25
|
-
description: Classy is a collection of
|
25
|
+
description: Classy is a collection of metaprogramming-heavy modules which you can extend in order to give various capabilities to your Ruby classes. For example, SubclassAware lets a class know about all of its subclasses (and sub-subclasses, etc), and Aliasable lets you refer to classes via symbols (useful for creating friendly DSLs).
|
26
26
|
email: github@djspinmonkey.com
|
27
27
|
executables: []
|
28
28
|
|
@@ -77,3 +77,4 @@ test_files:
|
|
77
77
|
- spec/aliasable_spec.rb
|
78
78
|
- spec/spec_helper.rb
|
79
79
|
- spec/subclass_aware_spec.rb
|
80
|
+
- spec/templatable_spec.rb
|