attributes 3.3.0 → 3.5.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 CHANGED
@@ -22,6 +22,10 @@ SYNOPSIS
22
22
  in particular the solutions of Christian Neukirchen and Florian Gross.
23
23
 
24
24
  HISTORY
25
+ 3.5.0
26
+ migrated to a pervasives based impl to attributes should work on any
27
+ object - even blankslate objects
28
+
25
29
  3.3.0
26
30
 
27
31
  moved to an instance variable-less model using an module level closure for
@@ -183,5 +187,5 @@ SAMPLES
183
187
 
184
188
  ~ > ruby samples/e.rb
185
189
 
186
- #<Config:0x220b0 @port=80, @host="codeforpeople.org">
190
+ #<Config:0x1fd4c @port=80, @host="codeforpeople.org">
187
191
 
data/README.tmpl CHANGED
@@ -22,6 +22,10 @@ SYNOPSIS
22
22
  in particular the solutions of Christian Neukirchen and Florian Gross.
23
23
 
24
24
  HISTORY
25
+ 3.5.0
26
+ migrated to a pervasives based impl to attributes should work on any
27
+ object - even blankslate objects
28
+
25
29
  3.3.0
26
30
 
27
31
  moved to an instance variable-less model using an module level closure for
data/a.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'attributes'
2
+
3
+ class A
4
+ attribute 'a'
5
+ end
6
+
7
+ class B < A
8
+ attribute 'b'
9
+ end
10
+
11
+ p A.attributes
12
+ p A.new.attributes
13
+ p B.attributes
14
+ p B.new.attributes
File without changes
data/gemspec.rb CHANGED
@@ -1,8 +1,10 @@
1
+
1
2
  lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
2
3
 
3
4
  require 'rubygems'
4
5
 
5
6
  Gem::Specification::new do |spec|
7
+ $VERBOSE = nil
6
8
  spec.name = lib
7
9
  spec.version = version
8
10
  spec.platform = Gem::Platform::RUBY
@@ -16,8 +18,11 @@ Gem::Specification::new do |spec|
16
18
 
17
19
  spec.has_rdoc = File::exist? "doc"
18
20
  spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
21
+ spec.add_dependency 'pervasives', '>= 0'
22
+
23
+ spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
19
24
 
20
25
  spec.author = "Ara T. Howard"
21
- spec.email = "ara.t.howard@noaa.gov"
26
+ spec.email = "ara.t.howard@gmail.com"
22
27
  spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
23
28
  end
@@ -1,5 +1,7 @@
1
+ require 'pervasives'
2
+
1
3
  module Attributes
2
- VERSION = '3.3.0'
4
+ VERSION = '3.5.0'
3
5
  def self.version() VERSION end
4
6
 
5
7
  def attributes *a, &b
@@ -12,25 +14,31 @@ module Attributes
12
14
 
13
15
  names_and_defaults.each do |name, default|
14
16
  init = b || lambda { default }
15
- ivar, getter, setter, query = "@#{ name }", "#{ name }", "#{ name }=", "#{ name }?"
17
+ ivar, getter, setter, query, banger =
18
+ "@#{ name }", "#{ name }", "#{ name }=", "#{ name }?", "#{ name }!"
16
19
 
17
20
  define_method(setter) do |value|
18
- instance_variable_set ivar, value
21
+ __pervasive__('instance_variable_set', ivar, value)
19
22
  end
20
23
 
21
24
  define_method(getter) do |*value|
22
25
  unless value.empty?
23
- send setter, value.shift
26
+ __pervasive__('send', setter, value.shift)
24
27
  else
25
- defined = instance_eval "defined? #{ ivar }"
26
- send setter, instance_eval(&init) unless defined
27
- instance_variable_get ivar
28
+ defined = __pervasive__('instance_eval', "defined? #{ ivar }")
29
+ __pervasive__('send', setter, __pervasive__('instance_eval', &init)) unless defined
30
+ __pervasive__('instance_variable_get', ivar)
28
31
  end
29
32
  end
30
33
 
34
+ define_method(banger) do
35
+ __pervasive__('send', setter, __pervasive__('instance_eval', &init))
36
+ __pervasive__('instance_variable_get', ivar)
37
+ end
38
+
31
39
  alias_method query, getter
32
40
 
33
- (attributes << name).uniq!
41
+ (attributes << name.to_s).uniq!
34
42
  attributes
35
43
  end
36
44
  else
@@ -41,11 +49,12 @@ module Attributes
41
49
  class << self
42
50
  self
43
51
  end
44
- singleton_class.module_eval <<-code
52
+ klass = self
53
+ singleton_class.module_eval do
45
54
  attribute_list = []
46
- define_method('attribute_list'){ attribute_list }
55
+ define_method('attribute_list'){ klass == self ? attribute_list : raise(NameError) }
47
56
  alias_method '__attribute_list__', 'attribute_list'
48
- code
57
+ end
49
58
  __attribute_list__
50
59
  end
51
60
  end
@@ -65,4 +74,6 @@ class Object
65
74
  %w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
66
75
  end
67
76
 
68
- class Module; include Attributes; end
77
+ class Module
78
+ include Attributes
79
+ end
data/lib/attributes.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'pervasives'
2
+
1
3
  module Attributes
2
- VERSION = '3.3.0'
4
+ VERSION = '3.5.0'
3
5
  def self.version() VERSION end
4
6
 
5
7
  def attributes *a, &b
@@ -12,25 +14,31 @@ module Attributes
12
14
 
13
15
  names_and_defaults.each do |name, default|
14
16
  init = b || lambda { default }
15
- ivar, getter, setter, query = "@#{ name }", "#{ name }", "#{ name }=", "#{ name }?"
17
+ ivar, getter, setter, query, banger =
18
+ "@#{ name }", "#{ name }", "#{ name }=", "#{ name }?", "#{ name }!"
16
19
 
17
20
  define_method(setter) do |value|
18
- instance_variable_set ivar, value
21
+ __pervasive__('instance_variable_set', ivar, value)
19
22
  end
20
23
 
21
24
  define_method(getter) do |*value|
22
25
  unless value.empty?
23
- send setter, value.shift
26
+ __pervasive__('send', setter, value.shift)
24
27
  else
25
- defined = instance_eval "defined? #{ ivar }"
26
- send setter, instance_eval(&init) unless defined
27
- instance_variable_get ivar
28
+ defined = __pervasive__('instance_eval', "defined? #{ ivar }")
29
+ __pervasive__('send', setter, __pervasive__('instance_eval', &init)) unless defined
30
+ __pervasive__('instance_variable_get', ivar)
28
31
  end
29
32
  end
30
33
 
34
+ define_method(banger) do
35
+ __pervasive__('send', setter, __pervasive__('instance_eval', &init))
36
+ __pervasive__('instance_variable_get', ivar)
37
+ end
38
+
31
39
  alias_method query, getter
32
40
 
33
- (attributes << name).uniq!
41
+ (attributes << name.to_s).uniq!
34
42
  attributes
35
43
  end
36
44
  else
@@ -41,11 +49,12 @@ module Attributes
41
49
  class << self
42
50
  self
43
51
  end
44
- singleton_class.module_eval <<-code
52
+ klass = self
53
+ singleton_class.module_eval do
45
54
  attribute_list = []
46
- define_method('attribute_list'){ attribute_list }
55
+ define_method('attribute_list'){ klass == self ? attribute_list : raise(NameError) }
47
56
  alias_method '__attribute_list__', 'attribute_list'
48
- code
57
+ end
49
58
  __attribute_list__
50
59
  end
51
60
  end
@@ -65,4 +74,6 @@ class Object
65
74
  %w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
66
75
  end
67
76
 
68
- class Module; include Attributes; end
77
+ class Module
78
+ include Attributes
79
+ end
metadata CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: attributes
5
5
  version: !ruby/object:Gem::Version
6
- version: 3.3.0
7
- date: 2007-06-04 00:00:00 -06:00
6
+ version: 3.5.0
7
+ date: 2007-07-02 00:00:00 -06:00
8
8
  summary: attributes
9
9
  require_paths:
10
10
  - lib
11
- email: ara.t.howard@noaa.gov
11
+ email: ara.t.howard@gmail.com
12
12
  homepage: http://codeforpeople.com/lib/ruby/attributes/
13
13
  rubyforge_project:
14
14
  description:
@@ -29,12 +29,13 @@ post_install_message:
29
29
  authors:
30
30
  - Ara T. Howard
31
31
  files:
32
- - attributes-3.3.0.gem
32
+ - a.rb
33
+ - attributes-3.5.0.gem
33
34
  - gemspec.rb
34
35
  - gen_readme.rb
35
36
  - install.rb
36
37
  - lib
37
- - lib/attributes-3.3.0.rb
38
+ - lib/attributes-3.5.0.rb
38
39
  - lib/attributes.rb
39
40
  - README
40
41
  - README.tmpl
@@ -56,5 +57,13 @@ extensions: []
56
57
 
57
58
  requirements: []
58
59
 
59
- dependencies: []
60
-
60
+ dependencies:
61
+ - !ruby/object:Gem::Dependency
62
+ name: pervasives
63
+ version_requirement:
64
+ version_requirements: !ruby/object:Gem::Version::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version: