attributes 4.1.0 → 5.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 CHANGED
@@ -45,6 +45,63 @@ SYNOPSIS
45
45
  all this in < 100 lines of code
46
46
 
47
47
  HISTORY
48
+ 5.0.0
49
+ - added support for block caching. for example
50
+
51
+ - simple block caching:
52
+
53
+ class Filter
54
+ attribute :process
55
+ end
56
+
57
+ (( filter = Filter.new )).process{|line| line.upcase}
58
+
59
+ lines.each do |line|
60
+ p filter.process.call(line)
61
+ end
62
+
63
+ - using block caching to delay block evaluation/class-factory:
64
+
65
+ module MigrationDSL
66
+ attribute :migration
67
+
68
+ def migration_class
69
+ model = self
70
+ Class.new(::ActiveRecord::Migration) do
71
+ singleton_class =
72
+ class << self
73
+ self
74
+ end
75
+ singleton_class.module_eval{ attribute :model => model }
76
+ singleton_class.module_eval &model.migration
77
+ end
78
+ end
79
+ end
80
+
81
+ class Table < ActiveRecord::Base
82
+ extend MigrationDSL
83
+ end
84
+
85
+ class Jobs < Table
86
+ migration do
87
+ def up
88
+ create_table model.table_name, :primary_key => model.primary_key do |t|
89
+ t.column 'rockin', :text
90
+ end
91
+ end
92
+
93
+ def down
94
+ create_table model.table_name
95
+ end
96
+ end
97
+ end
98
+
99
+ ...
100
+
101
+ JobsMigration = Jobs.migration_class
102
+
103
+ - cleaned up some warnings under 'ruby -d'
104
+
48
105
  4.1.0
49
106
  - 4.0.0 introduced a bug where a query (foo?) would not initialize a var -
50
107
  4.1.0 fixes that
@@ -230,7 +287,7 @@ SAMPLES
230
287
 
231
288
  ~ > ruby samples/e.rb
232
289
 
233
- #<Config:0x1ffb8 @port=80, @host="codeforpeople.org">
290
+ #<Config:0x1fb58 @port=80, @host="codeforpeople.org">
234
291
 
235
292
 
236
293
  <========< samples/f.rb >========>
@@ -45,6 +45,63 @@ SYNOPSIS
45
45
  all this in < 100 lines of code
46
46
 
47
47
  HISTORY
48
+ 5.0.0
49
+ - added support for block caching. for example
50
+
51
+ - simple block caching:
52
+
53
+ class Filter
54
+ attribute :process
55
+ end
56
+
57
+ (( filter = Filter.new )).process{|line| line.upcase}
58
+
59
+ lines.each do |line|
60
+ p filter.process.call(line)
61
+ end
62
+
63
+ - using block caching to delay block evaluation/class-factory:
64
+
65
+ module MigrationDSL
66
+ attribute :migration
67
+
68
+ def migration_class
69
+ model = self
70
+ Class.new(::ActiveRecord::Migration) do
71
+ singleton_class =
72
+ class << self
73
+ self
74
+ end
75
+ singleton_class.module_eval{ attribute :model => model }
76
+ singleton_class.module_eval &model.migration
77
+ end
78
+ end
79
+ end
80
+
81
+ class Table < ActiveRecord::Base
82
+ extend MigrationDSL
83
+ end
84
+
85
+ class Jobs < Table
86
+ migration do
87
+ def up
88
+ create_table model.table_name, :primary_key => model.primary_key do |t|
89
+ t.column 'rockin', :text
90
+ end
91
+ end
92
+
93
+ def down
94
+ create_table model.table_name
95
+ end
96
+ end
97
+ end
98
+
99
+ ...
100
+
101
+ JobsMigration = Jobs.migration_class
102
+
103
+ - cleaned up some warnings under 'ruby -d'
104
+
48
105
  4.1.0
49
106
  - 4.0.0 introduced a bug where a query (foo?) would not initialize a var -
50
107
  4.1.0 fixes that
data/b.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'lib/attributes.rb'
2
+ require 'rubygems'
3
+ require 'active_record'
4
+ require 'yaml'
5
+
6
+ options = YAML.load <<-txt
7
+ adapter: postgresql
8
+ database: votelink
9
+ username: www
10
+ host: localhost
11
+ encoding: UTF8
12
+ txt
13
+ ActiveRecord::Base.establish_connection options
14
+
15
+ module MigrationDSL
16
+ attribute :migration
17
+
18
+ def migration_class
19
+ model = self
20
+ Class.new(::ActiveRecord::Migration) do
21
+ singleton_class =
22
+ class << self
23
+ self
24
+ end
25
+ singleton_class.module_eval{ attribute :model => model }
26
+ singleton_class.module_eval &model.migration
27
+ end
28
+ end
29
+ end
30
+
31
+ class Table < ActiveRecord::Base
32
+ extend MigrationDSL
33
+ end
34
+
35
+ class Jobs < Table
36
+ migration do
37
+ def up
38
+ create_table model.table_name, :primary_key => model.primary_key do |t|
39
+ t.column 'rockin', :text
40
+ end
41
+ end
42
+
43
+ def down
44
+ create_table model.table_name
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Attributes
2
- Attributes::VERSION = '4.1.0' unless defined? Attributes::VERSION
2
+ Attributes::VERSION = '5.0.0' unless defined? Attributes::VERSION
3
3
  def self.version() Attributes::VERSION end
4
4
 
5
5
  class List < ::Array
@@ -40,20 +40,22 @@ module Attributes
40
40
 
41
41
  initialize = b || lambda { default }
42
42
  initializer = lambda do |this|
43
- Object.instance_method('instance_eval').bind(this).call &initialize
43
+ Object.instance_method('instance_eval').bind(this).call(&initialize)
44
44
  end
45
45
  initializer_id = initializer.object_id
46
46
  __attributes__.initializers[name] = initializer
47
47
 
48
48
  module_eval <<-code
49
- def #{ name }=(value)
50
- @#{ name } = value
49
+ def #{ name }=(*value, &block)
50
+ value.unshift block if block
51
+ @#{ name } = value.first
51
52
  end
52
53
  code
53
54
 
54
55
  module_eval <<-code
55
- def #{ name }(*value)
56
- return self.#{ name } = value.first unless value.empty?
56
+ def #{ name }(*value, &block)
57
+ value.unshift block if block
58
+ return self.send('#{ name }=', value.first) unless value.empty?
57
59
  #{ name }! unless defined? @#{ name }
58
60
  @#{ name }
59
61
  end
@@ -106,7 +108,7 @@ class Object
106
108
  class << self
107
109
  self
108
110
  end
109
- sc.attributes *a, &b
111
+ sc.attributes(*a, &b)
110
112
  end
111
113
  %w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
112
114
  end
@@ -1,5 +1,5 @@
1
1
  module Attributes
2
- Attributes::VERSION = '4.1.0' unless defined? Attributes::VERSION
2
+ Attributes::VERSION = '5.0.0' unless defined? Attributes::VERSION
3
3
  def self.version() Attributes::VERSION end
4
4
 
5
5
  class List < ::Array
@@ -40,20 +40,22 @@ module Attributes
40
40
 
41
41
  initialize = b || lambda { default }
42
42
  initializer = lambda do |this|
43
- Object.instance_method('instance_eval').bind(this).call &initialize
43
+ Object.instance_method('instance_eval').bind(this).call(&initialize)
44
44
  end
45
45
  initializer_id = initializer.object_id
46
46
  __attributes__.initializers[name] = initializer
47
47
 
48
48
  module_eval <<-code
49
- def #{ name }=(value)
50
- @#{ name } = value
49
+ def #{ name }=(*value, &block)
50
+ value.unshift block if block
51
+ @#{ name } = value.first
51
52
  end
52
53
  code
53
54
 
54
55
  module_eval <<-code
55
- def #{ name }(*value)
56
- return self.#{ name } = value.first unless value.empty?
56
+ def #{ name }(*value, &block)
57
+ value.unshift block if block
58
+ return self.send('#{ name }=', value.first) unless value.empty?
57
59
  #{ name }! unless defined? @#{ name }
58
60
  @#{ name }
59
61
  end
@@ -106,7 +108,7 @@ class Object
106
108
  class << self
107
109
  self
108
110
  end
109
- sc.attributes *a, &b
111
+ sc.attributes(*a, &b)
110
112
  end
111
113
  %w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
112
114
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: attributes
5
5
  version: !ruby/object:Gem::Version
6
- version: 4.1.0
7
- date: 2007-10-18 00:00:00 -06:00
6
+ version: 5.0.0
7
+ date: 2007-11-07 00:00:00 -07:00
8
8
  summary: attributes
9
9
  require_paths:
10
10
  - lib
@@ -30,11 +30,12 @@ authors:
30
30
  - Ara T. Howard
31
31
  files:
32
32
  - a.rb
33
+ - b.rb
33
34
  - gemspec.rb
34
35
  - gen_readme.rb
35
36
  - install.rb
36
37
  - lib
37
- - lib/attributes-4.1.0.rb
38
+ - lib/attributes-5.0.0.rb
38
39
  - lib/attributes.rb
39
40
  - README
40
41
  - README.tmpl