glue 0.23.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
data/ProjectInfo ADDED
@@ -0,0 +1,57 @@
1
+ --- %YAML:1.0
2
+
3
+ TITLE : &title Glue
4
+ NAME : &pkg glue
5
+ VERSION : '0.24.0'
6
+ STATUS : beta
7
+
8
+ AUTHOR : George Moschovitis
9
+ EMAIL : &email gm@navel.gr
10
+ HOMEPAGE : "http://www.nitrohq.com"
11
+
12
+ SUMMARY: Utility methods and classes for Nitro.
13
+
14
+ DESCRIPTION: >
15
+ Utility methods and classes for Nitro.
16
+
17
+ DEPENDENCIES:
18
+ - [ facets, '= 2005.10.15' ]
19
+ - [ cmdparse, '= 2.0.0' ]
20
+
21
+ DISTRIBUTE: [ gem, tgz, zip ]
22
+
23
+ RUBYFORGE:
24
+ PROJECT: 'nitro'
25
+ USERNAME: 'gmosx'
26
+
27
+ # Anything to require upfront?
28
+ #TEST:
29
+ # fixture: ''
30
+
31
+ ANNOUNCE:
32
+ to: george.moschovitis@gmail.com
33
+ from: gm@navel.gr
34
+ domain: navel.gr
35
+ server: mail
36
+ port: 25 #587
37
+ account: gm@navel.gr
38
+ authtype: login #cram_md5 #plain
39
+ sectype: tls # ~, tls, ssl (tls is broke)
40
+ file: ANN
41
+ slogan: Glue
42
+
43
+
44
+
45
+ links:
46
+ - http://www.nitrohq.com
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Glue 0.23.0 README
1
+ = Glue 0.24.0 README
2
2
 
3
3
  Useful utilites and methods.
4
4
 
data/Rakefile CHANGED
@@ -55,8 +55,8 @@ spec = Gem::Specification.new do |s|
55
55
  end
56
56
  s.summary = 'Glue utilities'
57
57
  s.description = 'A collection of utilities and useful classes'
58
- s.add_dependency 'nano', '>= 0.8.2'
59
- s.add_dependency 'mega', '>= 0.3.1'
58
+ # s.add_dependency 'facets', '= 0.8.2'
59
+ # s.add_dependency 'cmdparse', '= 2.0.0'
60
60
 
61
61
  s.required_ruby_version = '>= 1.8.2'
62
62
 
data/doc/RELEASES CHANGED
@@ -1,3 +1,19 @@
1
+ == Version 0.24.0
2
+
3
+ * Totaly recoded annotation / property system. The property
4
+ system is now based on Facet annotations and inheritors.
5
+ You can now annotate every object, attribute or method
6
+ in Nitro. For example you can annotate your actions with
7
+ routing rules or sitemap strings etc, etc. One unified
8
+ system for annotations and metadata is used throughout
9
+ the whole Framework.
10
+
11
+ * Fixed minor Ruby 1.8.3 compatibility issues.
12
+
13
+ * Even better integration with Ruby Facets.
14
+
15
+ * Tons of bug fixes and small but useful features.
16
+
1
17
  == Version 0.23.0
2
18
 
3
19
  Major cleanup, this release marks a bold step towards Nano/Nitro
data/lib/glue.rb CHANGED
@@ -11,9 +11,17 @@
11
11
  require 'English'
12
12
  require 'pp'
13
13
 
14
+ require 'mega/null'
15
+
14
16
  require 'glue/property'
15
17
  require 'glue/attribute'
16
18
 
19
+ # Fix for Mega.
20
+
21
+ class NullClass
22
+ def [](key); nil; end
23
+ end
24
+
17
25
  class NilClass
18
26
  # quite usefull for error tolerant apps.
19
27
  # a bit dangerous? Will have to rethink this.
@@ -56,7 +64,7 @@ module Glue
56
64
 
57
65
  # The version.
58
66
 
59
- Version = '0.23.0'
67
+ Version = '0.24.0'
60
68
 
61
69
  # Library path.
62
70
 
data/lib/glue/aspects.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'glue/property'
1
+ require 'mega/inheritor'
2
2
 
3
3
  module Glue
4
4
 
@@ -33,8 +33,8 @@ end
33
33
  #
34
34
  # module Timestamped
35
35
  # pre :on => :og_insert { |this| this.create_time = Time.now }
36
- # pre :on => :og_update { |this| this.update_time = Time.now }
37
- # pre :on => [:og_insert, :og_update] { |this| this.create_time = Time.now }
36
+ # pre :on => :og_update { |this| this.update_time = Time.now }
37
+ # pre :on => [:og_insert, :og_update] { |this| this.create_time = Time.now }
38
38
  # end
39
39
 
40
40
  module Aspects
@@ -72,6 +72,9 @@ module Aspects
72
72
  # Include Modules that define advices.
73
73
 
74
74
  def self.include_advice_modules(target)
75
+ add_advices = []
76
+ del_advices = []
77
+
75
78
  for a in target.advices
76
79
  if a.code.is_a?(Module) and (!a.code.class.ancestors.include?(Class))
77
80
  target.module_eval %{ include #{a.code} }
@@ -81,22 +84,28 @@ module Aspects
81
84
  method = (a.options[:pre] || 'pre').to_s
82
85
  if a.code.instance_methods.include?(method)
83
86
  options.update(:where => :prepend, :join => :pre)
84
- target.advices << Advice.new(method, options)
87
+ add_advices << Advice.new(method.to_sym, options)
85
88
  end
86
89
 
87
90
  method = (a.options[:post] || 'post').to_s
88
91
  if a.code.instance_methods.include?(method)
89
92
  options.update(:where => :append, :join => :post)
90
- target.advices << Advice.new(method, options)
93
+ add_advices << Advice.new(method.to_sym, options)
91
94
  end
95
+
96
+ del_advices << a
92
97
  end
93
98
  end
94
99
 
95
- # Remove the original advice.
96
-
97
- target.advices.delete_if do |a|
98
- a.code.is_a?(Module) and (!a.code.class.ancestors.include?(Class))
100
+ # Delete the original advices.
101
+
102
+ for a in del_advices
103
+ target.advices!.delete(a)
99
104
  end
105
+
106
+ # Add the new advices.
107
+
108
+ target.advices!.concat(add_advices)
100
109
  end
101
110
 
102
111
  # Generates the code to call the aspects.
@@ -142,18 +151,7 @@ module Aspects
142
151
  def self.append_features(base)
143
152
  super
144
153
  base.extend(ClassMethods)
145
-
146
- base.module_eval %{
147
- Glue::PropertyUtils.enchant(self)
148
-
149
- def self.advices
150
- __meta[:advices] || []
151
- end
152
-
153
- def self.advices=(advices)
154
- __meta[:advices] = advices
155
- end
156
- }
154
+ base.inheritor :advices, [], :+
157
155
  end
158
156
 
159
157
  module ClassMethods
@@ -168,16 +166,18 @@ module Aspects
168
166
  options.update(args.pop) if args.last.is_a?(Hash)
169
167
 
170
168
  if block_given?
171
- advices = [ Advice.new(block, options) ]
169
+ new_advices = [ Advice.new(block, options) ]
172
170
  else
173
- advices = args.collect { |a| Advice.new(a, options) }
171
+ new_advices = args.collect { |a| Advice.new(a, options) }
174
172
  end
175
-
173
+ =begin
176
174
  if options[:where] == :prepend
177
175
  self.advices = advices + self.advices
178
176
  else
179
177
  self.advices = self.advices + advices
180
178
  end
179
+ =end
180
+ self.advices!.concat(new_advices)
181
181
  end
182
182
  alias_method :before, :pre
183
183
 
@@ -191,16 +191,18 @@ module Aspects
191
191
  options.update(args.pop) if args.last.is_a?(Hash)
192
192
 
193
193
  if block_given?
194
- advices = [ Advice.new(block, options) ]
194
+ new_advices = [ Advice.new(block, options) ]
195
195
  else
196
- advices = args.collect { |a| Advice.new(a, options) }
196
+ new_advices = args.collect { |a| Advice.new(a, options) }
197
197
  end
198
-
198
+ =begin
199
199
  if options[:where] == :prepend
200
200
  self.advices = advices + self.advices
201
201
  else
202
202
  self.advices = self.advices + advices
203
203
  end
204
+ =end
205
+ self.advices!.concat(new_advices)
204
206
  end
205
207
  alias_method :after, :post
206
208
 
@@ -215,7 +217,7 @@ module Aspects
215
217
  options.update(args.pop) if args.last.is_a?(Hash)
216
218
 
217
219
  for aspect in args
218
- self.advices << Advice.new(aspect, options)
220
+ self.advices! << Advice.new(aspect, options)
219
221
  end
220
222
  end
221
223
  alias_method :around, :wrap
data/lib/glue/bit.rb ADDED
@@ -0,0 +1,53 @@
1
+ # (c) 2005 George Moschovitis <gm@navel.gr>
2
+
3
+ def bitmask(bit)
4
+ 1 << bit
5
+ end
6
+
7
+ def set_bit(num, bit)
8
+ mask = bitmask(bit)
9
+ num |= mask
10
+ end
11
+
12
+ def clear_bit(num, bit)
13
+ mask = bitmask(bit)
14
+ num &= mask
15
+ end
16
+
17
+ def test_bit(num, bit)
18
+ mask = bitmask(bit)
19
+ (num & mask) != 0
20
+ end
21
+ alias :bit? :test_bit
22
+ alias :bit_set? :test_bit
23
+
24
+ def set_bitmask(num, mask)
25
+ num |= mask
26
+ end
27
+
28
+ def test_bitmask(num, mask)
29
+ num &= mask
30
+ end
31
+ alias :bitmask? :test_bitmask
32
+
33
+ if $0 == __FILE__
34
+ a = 1
35
+ m = bitmask(4)
36
+ a = set_bitmask(a, m)
37
+ p a
38
+ p test_bitmask(a, m)
39
+ p test_bit(a, 4)
40
+ p bit_set?(a, 4)
41
+ p test_bit(a, 12)
42
+ end
43
+
44
+ __END__
45
+
46
+ Is it possible to get an interface like this?
47
+
48
+ a = 1
49
+ a.set_bit(3)
50
+ if a.test_bit(3)
51
+
52
+ if a.bit_set? 3
53
+ end
@@ -1,6 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
- require 'nano/object/constant'
3
+ require 'nano/kernel/constant'
4
4
  require 'mega/synchash'
5
5
 
6
6
  require 'glue/attribute'
data/lib/glue/fixture.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'nano/object/constant'
1
+ require 'nano/kernel/constant'
2
2
 
3
3
  require 'mega/orm_support'
4
4
 
data/lib/glue/flexob.rb CHANGED
@@ -11,6 +11,15 @@ class Flexob < OpenStruct
11
11
  end
12
12
  end
13
13
  alias_method :set, :update
14
+ alias_method :merge, :update
15
+
16
+ def fetch(key, default = nil)
17
+ if @table.has_key?(key)
18
+ @table[key.to_sym]
19
+ else
20
+ default
21
+ end
22
+ end
14
23
 
15
24
  def []=(key, val)
16
25
  @table[key.to_sym] = val
@@ -23,7 +32,10 @@ class Flexob < OpenStruct
23
32
  def each(&block)
24
33
  @table.each(&block)
25
34
  end
26
-
35
+
36
+ def has_key?(key)
37
+ @table.has_key?(key)
38
+ end
39
+
27
40
  end
28
41
 
29
- # * George Moschovitis <gm@navel.gr>
data/lib/glue/helper.rb CHANGED
@@ -12,6 +12,7 @@ module Glue
12
12
  module Helpers
13
13
 
14
14
  def self.append_features(base)
15
+ super
15
16
  base.module_eval do
16
17
  def self.helper(*modules)
17
18
  for mod in modules
data/lib/glue/logger.rb CHANGED
@@ -43,7 +43,7 @@ class Logger
43
43
  unless expr.respond_to? :to_str
44
44
  warn "trace: Can't evaluate the given value: #{caller.first}"
45
45
  else
46
- require 'nano/binding/of_caller'
46
+ require 'nano/binding/self/of_caller'
47
47
 
48
48
  Binding.of_caller do |b|
49
49
  value = b.eval(expr.to_str)
@@ -82,20 +82,20 @@ class Logger
82
82
  # logger.format do |severity, timestamp, msg, progname|
83
83
  # "#{progname}@#{timestamp} - #{severity}::#{msg}"
84
84
  # end
85
-
85
+
86
86
  def setup_format(&format_proc)
87
- raise 'Formating block needed' unless format_proc
88
- @format_proc = format_proc
87
+ # raise 'Formating block needed' unless format_proc
88
+ # @format_proc = format_proc
89
89
  end
90
90
 
91
91
  private
92
92
 
93
93
  # hackish use of *args, give me some love.
94
94
 
95
+ alias_method :old_format_message, :format_message
95
96
  def format_message(*args)
96
- @format_proc ? @format_proc.call(*args) : super(*args)
97
+ @format_proc ? @format_proc.call(*args) : old_format_message(*args)
97
98
  end
98
-
99
99
  end
100
100
 
101
101
  # Global logger interface. This provides an alternative
@@ -103,9 +103,9 @@ end
103
103
 
104
104
  class Logger
105
105
 
106
- SIMPLE_FORMAT = "%5s: %s\n"
106
+ SIMPLE_FORMAT = "%5s: %s\n"
107
107
  @@global_logger = Logger.new(STDERR)
108
- @@global_logger.setup_format do |severity, timestamp, msg, progname|
108
+ @@global_logger.setup_format do |severity, timestamp, progname, msg|
109
109
  SIMPLE_FORMAT % [severity, msg]
110
110
  end
111
111
 
@@ -114,12 +114,12 @@ class Logger
114
114
  def self.set(logger)
115
115
  if logger.is_a?(String)
116
116
  @@global_logger = Logger.new(logger)
117
- @@global_logger.setup_format do |severity, timestamp, msg, progname|
117
+ @@global_logger.setup_format do |severity, timestamp, progname, msg|
118
118
  SIMPLE_FORMAT % [severity, msg]
119
119
  end
120
120
  elsif logger.is_a?(Logger)
121
121
  @@global_logger = logger
122
- @@global_logger.setup_format do |severity, timestamp, msg, progname|
122
+ @@global_logger.setup_format do |severity, timestamp, progname, msg|
123
123
  SIMPLE_FORMAT % [severity, msg]
124
124
  end
125
125
  else
@@ -155,7 +155,7 @@ class Logger
155
155
  unless expr.respond_to? :to_str
156
156
  warn "trace: Can't evaluate the given value: #{caller.first}"
157
157
  else
158
- require 'nano/binding/of_caller'
158
+ require 'nano/binding/self/of_caller'
159
159
 
160
160
  Binding.of_caller do |b|
161
161
  value = eval(expr.to_str, b)
@@ -23,9 +23,7 @@ module Glue
23
23
  # sudo postfix start
24
24
 
25
25
  module IncomingMailer
26
- def self.included(base)
27
- base.extend ClassMethods
28
- end
26
+ on_included %{ base.extend ClassMethods }
29
27
 
30
28
  # You can overide this class for specialized handling.
31
29