attic 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,15 @@
1
1
  ATTIC, CHANGES
2
2
 
3
+ #### 0.5.3 (2011-02-11) ###############################
4
+
5
+ * FIXED: Don't redefine Object::NOMETACLASS
6
+ * CHANGE: Updated tests to Tryouts 2
7
+ * CHANGE: Move attic/mixins content to attic.rb
8
+
9
+
3
10
  #### 0.5.2 (2010-02-15) ###############################
4
11
 
5
- * CHANGE: Remove hanna dependency
12
+ * CHANGE: Remove hanna dependency [Diego Elio 'Flameeyes' Pettenò]
6
13
 
7
14
  #### 0.5.0 (2009-11-29) ###############################
8
15
 
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "attic"
3
3
  s.rubyforge_project = "attic"
4
- s.version = "0.5.2"
4
+ s.version = "0.5.3"
5
5
  s.summary = "A place to hide private instance variables in your Ruby objects."
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -22,11 +22,6 @@
22
22
  # Update --main to reflect the default page to display
23
23
  s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
24
24
 
25
- # = DEPENDENCIES =
26
- # Add all gem dependencies
27
- #s.add_dependency 'name1'
28
- #s.add_dependency 'name2', '>= 0.0.0'
29
-
30
25
  # = MANIFEST =
31
26
  # The complete list of files to be included in the release. When GitHub packages your gem,
32
27
  # it doesn't allow you to run any command that accesses the filesystem. You will get an
@@ -40,7 +35,6 @@
40
35
  Rakefile
41
36
  attic.gemspec
42
37
  lib/attic.rb
43
- lib/attic/mixins.rb
44
38
  try/01_mixins_tryouts.rb
45
39
  try/10_attic_tryouts.rb
46
40
  try/20_accessing_tryouts.rb
@@ -1,12 +1,82 @@
1
1
 
2
- require 'attic/mixins'
2
+ class NoMetaClass < RuntimeError
3
+ end
4
+
5
+ # = Object
6
+ #
7
+ # These methods are copied directly from _why's metaid.rb.
8
+ # See: http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
9
+ class Object
10
+
11
+ unless defined?(::Object::NOMETACLASS)
12
+ # An Array of classes which do not have metaclasses.
13
+ NOMETACLASS = [Symbol, Fixnum].freeze
14
+ end
15
+
16
+ def nometaclass?
17
+ NOMETACLASS.member?(self)
18
+ end
19
+
20
+ def metaclass?
21
+ !NOMETACLASS.member?(self.class)
22
+ end
23
+
24
+ # A convenient method for getting the metaclass of the current object.
25
+ # i.e.
26
+ #
27
+ # class << self; self; end;
28
+ #
29
+ # NOTE: Some Ruby class do not have meta classes (see: NOMETACLASS).
30
+ # For these classes, this method returns the class itself. That means
31
+ # the instance variables will stored in the class itself.
32
+ def metaclass
33
+ if !self.metaclass?
34
+ raise NoMetaClass, self
35
+ else
36
+ class << self; self; end;
37
+ end
38
+ end
39
+
40
+ # Execute a block +&blk+ within the metaclass of the current object.
41
+ def meta_eval &blk; metaclass.instance_eval &blk; end
42
+
43
+ # Add an instance method called +name+ to metaclass for the current object.
44
+ # This is useful because it will be available as a singleton method
45
+ # to all subclasses too.
46
+ def meta_def name, &blk
47
+ meta_eval { define_method name, &blk }
48
+ end
49
+
50
+ # Add a class method called +name+ for the current object's class. This
51
+ # isn't so special but it maintains consistency with meta_def.
52
+ def class_def name, &blk
53
+ class_eval { define_method name, &blk }
54
+ end
55
+
56
+
57
+ # A convenient method for getting the metaclass of the metaclass
58
+ # i.e.
59
+ #
60
+ # self.metaclass.metaclass
61
+ #
62
+ def metametaclass; self.metaclass.metaclass; end
63
+
64
+ def metameta_eval &blk; metametaclass.instance_eval &blk; end
65
+
66
+ def metameta_def name, &blk
67
+ metameta_eval { define_method name, &blk }
68
+ end
69
+
70
+ end
71
+
72
+
3
73
 
4
74
  # = Attic
5
75
  #
6
76
  # A place to store instance variables.
7
77
  #
8
78
  module Attic
9
- VERSION = '0.5.2' unless defined?(VERSION)
79
+ VERSION = '0.5.3' unless defined?(VERSION)
10
80
 
11
81
  module InstanceMethods
12
82
  def attic_variables
@@ -1,13 +1,17 @@
1
- group "Mixins"
2
- library :attic, "lib"
1
+ require 'attic'
3
2
 
4
- tryouts "Object" do
5
- if Tryouts.sysinfo.ruby == "1.9.1"
6
- drill "has metaclass", 'Object' do
7
- Object.new.metaclass.superclass.to_s
8
- end
9
- drill "has metametaclass", '#<Class:Object>' do
10
- Object.new.metametaclass.superclass.to_s
11
- end
12
- end
13
- end
3
+ ## has metaclass", 'Object' do
4
+ if Tryouts.sysinfo.ruby.to_s == "1.9.1"
5
+ Object.new.metaclass.superclass.to_s
6
+ else
7
+ 'Object'
8
+ end
9
+ #=> 'Object'
10
+
11
+ ## has metametaclass", '#<Class:Object>' do
12
+ if Tryouts.sysinfo.ruby.to_s >= "1.9.1"
13
+ Object.new.metaclass.superclass.to_s
14
+ else
15
+ '#<Class:Object>'
16
+ end
17
+ #=> 'Object'
@@ -1,43 +1,41 @@
1
- group "Attic"
2
- library :attic, "lib"
3
- tryouts "Basics" do
1
+ require 'attic'
4
2
 
5
- drill "can extend Attic", true do
6
- class ::Worker
7
- extend Attic
8
- def kind() :true end
9
- end
10
- # 1.9 # 1.8
11
- Worker.methods.member?(:attic) || Worker.methods.member?('attic')
12
- end
3
+ ## can extend Attic
4
+ class ::Worker
5
+ extend Attic
6
+ def kind() :true end
7
+ end
8
+ # 1.9 # 1.8
9
+ Worker.methods.member?(:attic) || Worker.methods.member?('attic')
10
+ #=> true
13
11
 
14
- drill "can't include Attic raises exception", :exception, RuntimeError do
15
- class ::Worker
16
- include Attic
17
- end
12
+ ## can't include Attic raises exception
13
+ begin
14
+ class ::Worker
15
+ include Attic
18
16
  end
17
+ rescue => RuntimeError
18
+ :success
19
+ end
20
+ #=> :success
19
21
 
20
- drill "can define attic attribute", true do
21
- Worker.attic :size
22
- w = Worker.new
23
- #w.attic :size
24
- stash :instance_methods, Worker.instance_methods(false)
25
- stash :metamethods, Worker.methods.sort
26
- w.respond_to? :size
27
- end
28
-
29
- drill "can access attic attributes explicitly", 2 do
30
- w = Worker.new
31
- w.attic_variable_set :size, 2
32
- w.attic_variable_get :size
33
- end
22
+ ## can define attic attribute
23
+ Worker.attic :size
24
+ w = Worker.new
25
+ #w.attic :size
26
+ p Worker.instance_methods(false)
27
+ p Worker.methods.sort
28
+ w.respond_to? :size
29
+ #=> true
34
30
 
35
- drill "won't define a method if on already exists", :true do
36
- Worker.attic :kind
37
- a = Worker.new
38
- a.kind
39
- end
31
+ ## can access attic attributes explicitly"
32
+ w = Worker.new
33
+ w.attic_variable_set :size, 2
34
+ w.attic_variable_get :size
35
+ #=> 2
40
36
 
41
- end
42
-
43
-
37
+ ## won't define a method if on already exists
38
+ Worker.attic :kind
39
+ a = Worker.new
40
+ a.kind
41
+ #=> :true
@@ -1,34 +1,29 @@
1
- group "Attic"
2
- library :attic, "lib"
3
- tryouts "Setting and Getting" do
1
+ require 'attic'
2
+ class ::Worker
3
+ extend Attic
4
+ attic :size
5
+ end
6
+
4
7
 
5
- setup do
6
- class ::Worker
7
- extend Attic
8
- attic :size
9
- end
10
- end
8
+ ## save an instance variable the long way
9
+ w = Worker.new
10
+ w.metametaclass.instance_variable_set '@mattress', 'S&F'
11
+ w.metametaclass.instance_variable_get '@mattress'
12
+ #=> 'S&F'
11
13
 
12
- drill "save an instance variable the long way", 'S&F' do
13
- w = Worker.new
14
- w.metametaclass.instance_variable_set '@mattress', 'S&F'
15
- w.metametaclass.instance_variable_get '@mattress'
16
- end
14
+ ## save an instance variable the short way
15
+ w = Worker.new
16
+ w.size = :california_king
17
+ w.size
18
+ #=> :california_king
17
19
 
18
- drill "save an instance variable the short way", :california_king do
19
- w = Worker.new
20
- w.size = :california_king
21
- w.size
22
- end
20
+ ## new instances don't cross streams
21
+ w = Worker.new
22
+ w.size
23
+ #=> nil
23
24
 
24
- drill "new instances don't cross streams", nil do
25
- w = Worker.new
26
- w.size
27
- end
28
-
29
- drill "instance variables are hidden", [] do
30
- w = Worker.new
31
- w.metametaclass.instance_variable_set '@mattress', 'S&F'
32
- w.instance_variables
33
- end
34
- end
25
+ ## instance variables are hidden
26
+ w = Worker.new
27
+ w.metametaclass.instance_variable_set '@mattress', 'S&F'
28
+ w.instance_variables
29
+ ## []
@@ -1,38 +1,32 @@
1
- group "Attic"
2
- library :attic, "lib"
3
- tryouts "String Setting and Getting" do
1
+ require 'attic'
4
2
 
5
- drill "String can extend Attic", true do
3
+ ## String can extend Attic
6
4
  String.extend Attic
7
5
  String.respond_to? :attic
8
- end
6
+ #=> true
9
7
 
10
- drill "save an instance variable the long way", 'S&F' do
11
- s = ""
12
- s.metametaclass.instance_variable_set '@mattress', 'S&F'
13
- s.metametaclass.instance_variable_get '@mattress'
14
- end
8
+ ## save an instance variable the long way
9
+ s = ""
10
+ s.metametaclass.instance_variable_set '@mattress', 'S&F'
11
+ s.metametaclass.instance_variable_get '@mattress'
12
+ #=> 'S&F'
15
13
 
16
- drill "can create attributes", [:goodies] do
17
- String.attic :goodies
18
- end
14
+ ## can create attributes
15
+ String.attic :goodies
16
+ #=> [:goodies]
19
17
 
20
- drill "save an instance variable the short way", :california_king do
21
- s = ""
22
- s.goodies = :california_king
23
- stash :ivars, s.instance_variables
24
- stash :avars, s.attic_vars
25
- s.goodies
26
- end
18
+ ## save an instance variable the short way
19
+ s = ""
20
+ s.goodies = :california_king
21
+ p s.instance_variables
22
+ p s.attic_vars
23
+ s.goodies
24
+ #=> :california_king
27
25
 
28
- drill "String instances don't cross streams", false do
29
- String.extend Attic
30
- String.attic :name
31
- a = "any"
32
- a.name = :roger
33
- a.name == "".name
34
- end
35
-
36
-
37
-
38
- end
26
+ ## String instances don't cross streams
27
+ String.extend Attic
28
+ String.attic :name
29
+ a = "any"
30
+ a.name = :roger
31
+ a.name == "".name
32
+ #=> false
@@ -1,56 +1,51 @@
1
- group "No Meta Class"
2
- library :attic, "lib"
3
- tryouts "Basics" do
4
-
5
- dream :class, Array
6
- dream [Symbol, Fixnum]
7
- drill "has list of no metaclass classes" do
8
- Object::NOMETACLASS
9
- end
10
-
11
- dream :exception, NoMetaClass
12
- drill "Symbol metaclass raises exception" do
13
- :any.metaclass
14
- end
15
-
16
- drill "Symbol instances don't cross streams", [:roger, nil] do
17
- Symbol.extend Attic
18
- Symbol.attic :name
19
- a, b = :symbol1, :symbol2
20
- a.name = :roger
21
- [a.name, b.name]
22
- end
23
-
24
- drill "metaclass? method exists", true do
25
- Symbol.extend Attic
26
- :any.respond_to? :metaclass?
27
- end
28
-
29
- drill "metaclass? method is false for a Symbol", false do
30
- :any.metaclass?
31
- end
32
-
33
- dream [:@___attic_name]
34
- drill "A Symbol's attic vars appear in all_instance_variables" do
35
- Symbol.extend Attic
36
- Symbol.attic :name
37
- a, b = :symbol1, :symbol2
38
- a.name = :roger
39
- a.all_instance_variables
40
- end
41
-
42
- dream []
43
- drill "A Symbol's attic vars do not appear in instance_variables" do
44
- Symbol.extend Attic
45
- Symbol.attic :name
46
- a, b = :symbol1, :symbol2
47
- a.name = :roger
48
- a.instance_variables
49
- end
50
-
51
-
52
- drill "knows attic variables", [:name] do
53
- Symbol.attic_variables
54
- end
55
-
56
- end
1
+ require 'attic'
2
+
3
+ ## has list of no metaclass classes
4
+ Object::NOMETACLASS
5
+ #=> [Symbol, Fixnum]
6
+
7
+ ## Symbol metaclass raises exception
8
+ begin
9
+ :any.metaclass
10
+ rescue NoMetaClass
11
+ :success
12
+ end
13
+ #=> :success
14
+
15
+ ## Symbol instances don't cross streams
16
+ Symbol.extend Attic
17
+ Symbol.attic :name
18
+ a, b = :symbol1, :symbol2
19
+ a.name = :roger
20
+ [a.name, b.name]
21
+ #=> [:roger, nil]
22
+
23
+ ## metaclass? method exists
24
+ Symbol.extend Attic
25
+ :any.respond_to? :metaclass?
26
+ #=> true
27
+
28
+ ## metaclass? method is false for a Symbol", false do
29
+ :any.metaclass?
30
+ #=> false
31
+
32
+ ## A Symbol's attic vars appear in all_instance_variables" do
33
+ Symbol.extend Attic
34
+ Symbol.attic :name
35
+ a, b = :symbol1, :symbol2
36
+ a.name = :roger
37
+ a.all_instance_variables
38
+ #=> [:@___attic_name]
39
+
40
+
41
+ ## A Symbol's attic vars do not appear in instance_variables" do
42
+ Symbol.extend Attic
43
+ Symbol.attic :name
44
+ a, b = :symbol1, :symbol2
45
+ a.name = :roger
46
+ a.instance_variables
47
+ #=> []
48
+
49
+ ## knows attic variables", [:name] do
50
+ Symbol.attic_variables
51
+ #=> [:name]
@@ -1,23 +1,17 @@
1
- group "Attic"
2
- library :attic, "lib"
3
- tryouts "Explicit accessors" do
1
+ require 'attic'
4
2
 
5
- setup do
6
- class ::Worker
7
- extend Attic
8
- end
9
- end
3
+ class ::Worker
4
+ extend Attic
5
+ end
10
6
 
11
- drill "can set value", 100 do
12
- a = Worker.new
13
- a.attic_variable_set :space, 100
14
- a.attic_variable_get :space
15
- end
7
+ ## can set value", 100 do
8
+ a = Worker.new
9
+ a.attic_variable_set :space, 100
10
+ a.attic_variable_get :space
11
+ #=> 100
16
12
 
17
- drill "doesn't create accessor methods", false do
18
- a = Worker.new
19
- a.attic_variable_set :space, 100
20
- a.respond_to? :space
21
- end
22
-
23
- end
13
+ ## doesn't create accessor methods", false do
14
+ a = Worker.new
15
+ a.attic_variable_set :space, 100
16
+ a.respond_to? :space
17
+ #=> false
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ hash: 13
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 3
10
+ version: 0.5.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - Delano Mandelbaum
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-15 00:00:00 -05:00
18
+ date: 2011-02-11 00:00:00 -05:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -30,7 +36,6 @@ files:
30
36
  - Rakefile
31
37
  - attic.gemspec
32
38
  - lib/attic.rb
33
- - lib/attic/mixins.rb
34
39
  - try/01_mixins_tryouts.rb
35
40
  - try/10_attic_tryouts.rb
36
41
  - try/20_accessing_tryouts.rb
@@ -53,21 +58,27 @@ rdoc_options:
53
58
  require_paths:
54
59
  - lib
55
60
  required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
56
62
  requirements:
57
63
  - - ">="
58
64
  - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
59
68
  version: "0"
60
- version:
61
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
62
71
  requirements:
63
72
  - - ">="
64
73
  - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
65
77
  version: "0"
66
- version:
67
78
  requirements: []
68
79
 
69
80
  rubyforge_project: attic
70
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.5.2
71
82
  signing_key:
72
83
  specification_version: 3
73
84
  summary: A place to hide private instance variables in your Ruby objects.
@@ -1,68 +0,0 @@
1
- class NoMetaClass < RuntimeError
2
- end
3
-
4
- # = Object
5
- #
6
- # These methods are copied directly from _why's metaid.rb.
7
- # See: http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
8
- class Object
9
-
10
- # An Array of classes which do not have metaclasses.
11
- NOMETACLASS = [Symbol, Fixnum].freeze
12
-
13
- def nometaclass?
14
- NOMETACLASS.member?(self)
15
- end
16
-
17
- def metaclass?
18
- !NOMETACLASS.member?(self.class)
19
- end
20
-
21
- # A convenient method for getting the metaclass of the current object.
22
- # i.e.
23
- #
24
- # class << self; self; end;
25
- #
26
- # NOTE: Some Ruby class do not have meta classes (see: NOMETACLASS).
27
- # For these classes, this method returns the class itself. That means
28
- # the instance variables will stored in the class itself.
29
- def metaclass
30
- if !self.metaclass?
31
- raise NoMetaClass, self
32
- else
33
- class << self; self; end;
34
- end
35
- end
36
-
37
- # Execute a block +&blk+ within the metaclass of the current object.
38
- def meta_eval &blk; metaclass.instance_eval &blk; end
39
-
40
- # Add an instance method called +name+ to metaclass for the current object.
41
- # This is useful because it will be available as a singleton method
42
- # to all subclasses too.
43
- def meta_def name, &blk
44
- meta_eval { define_method name, &blk }
45
- end
46
-
47
- # Add a class method called +name+ for the current object's class. This
48
- # isn't so special but it maintains consistency with meta_def.
49
- def class_def name, &blk
50
- class_eval { define_method name, &blk }
51
- end
52
-
53
-
54
- # A convenient method for getting the metaclass of the metaclass
55
- # i.e.
56
- #
57
- # self.metaclass.metaclass
58
- #
59
- def metametaclass; self.metaclass.metaclass; end
60
-
61
- def metameta_eval &blk; metametaclass.instance_eval &blk; end
62
-
63
- def metameta_def name, &blk
64
- metameta_eval { define_method name, &blk }
65
- end
66
-
67
- end
68
-