glue 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Glue 0.22.0 README
1
+ = Glue 0.23.0 README
2
2
 
3
3
  Useful utilites and methods.
4
4
 
@@ -6,14 +6,14 @@ Useful utilites and methods.
6
6
  == Purpose
7
7
 
8
8
  Useful libraries are stored here. An attempt is made to
9
- graduate smaller libraries to the more general Facets
9
+ graduate smaller libraries to the more general Nano/Mega
10
10
  ruby project.
11
11
 
12
12
 
13
13
  == Licence
14
14
 
15
- Copyright (c) 2004-2005, George 'gmosx' Moschovitis (http://www.gmosx.com)
16
15
  Copyright (c) 2004-2005, Navel Ltd (http://www.navel.gr)
16
+ Copyright (c) 2004-2005, George 'gmosx' Moschovitis (http://www.gmosx.com)
17
17
 
18
18
  Glue (http://www.rubyforge.org/projects/nitro) is copyrighted free
19
19
  software created and maintained by George Moschovitis (mailto:gm@navel.gr)
data/Rakefile CHANGED
@@ -55,14 +55,14 @@ 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 'facets', '>= 0.7.2'
59
- #s.add_dependency 'flexmock', '>= 0.0.3'
58
+ s.add_dependency 'nano', '>= 0.8.2'
59
+ s.add_dependency 'mega', '>= 0.3.1'
60
60
 
61
61
  s.required_ruby_version = '>= 1.8.2'
62
62
 
63
63
  s.files = FileList[
64
64
  '[A-Z]*', 'install.rb', '{doc,lib,test,vendor}/**/*'
65
- ].exclude('.svn/**/*').exclude('**/*.log').to_a
65
+ ].exclude("_darcs").exclude("_darcs/**/*").exclude('**/*.log').to_a
66
66
 
67
67
  s.require_path = 'lib'
68
68
  s.autorequire = 'glue'
File without changes
@@ -1,3 +1,13 @@
1
+ == Version 0.23.0
2
+
3
+ Major cleanup, this release marks a bold step towards Nano/Nitro
4
+ integration.
5
+
6
+ * Moved some files to the Nano/Mega project.
7
+
8
+ * Dreprecated functionality already available in Nano/Mega.
9
+
10
+
1
11
  == Version 0.22.0
2
12
 
3
13
  * New mailer implementation.
@@ -1,13 +1,12 @@
1
1
  # = Glue
2
2
  #
3
- # General libraries used by various projects.
4
- #
5
- # Copyright (c) 2004-2005, George Moschovitis (http://www.gmosx.com)
6
3
  # Copyright (c) 2004-2005, Navel Ltd (http://www.navel.gr)
4
+ # Copyright (c) 2004-2005, George Moschovitis (http://www.gmosx.com)
7
5
  #
8
- # Glue is copyrighted free software created and maintained by
9
- # George Moschovitis (mailto:gm@navel.gr) and released under the
10
- # standard BSD Licence. For details consult the file doc/LICENCE.
6
+ # Glue (http://www.nitrohq.com) is copyrighted free software
7
+ # created and maintained by George Moschovitis (mailto:gm@navel.gr)
8
+ # and released under the standard BSD Licence. For details
9
+ # consult the file doc/LICENCE.
11
10
 
12
11
  require 'English'
13
12
  require 'pp'
@@ -16,7 +15,6 @@ require 'glue/property'
16
15
  require 'glue/attribute'
17
16
 
18
17
  class NilClass
19
-
20
18
  # quite usefull for error tolerant apps.
21
19
  # a bit dangerous? Will have to rethink this.
22
20
 
@@ -26,8 +24,7 @@ class NilClass
26
24
 
27
25
  def blank?
28
26
  true
29
- end
30
-
27
+ end
31
28
  end
32
29
 
33
30
  class Class
@@ -41,7 +38,6 @@ class Class
41
38
  end
42
39
 
43
40
  module Kernel
44
-
45
41
  # Pretty prints an exception/error object
46
42
  # usefull for helpfull debug messages
47
43
  #
@@ -54,14 +50,13 @@ module Kernel
54
50
  def pp_exception(ex)
55
51
  return %{#{ex.message}\n #{ex.backtrace.join("\n ")}\n LOGGED FROM: #{caller[0]}}
56
52
  end
57
-
58
53
  end
59
54
 
60
55
  module Glue
61
56
 
62
57
  # The version.
63
58
 
64
- Version = '0.22.0'
59
+ Version = '0.23.0'
65
60
 
66
61
  # Library path.
67
62
 
@@ -1,9 +1,9 @@
1
1
  require 'yaml'
2
2
 
3
- require 'facet/object/constant'
3
+ require 'nano/object/constant'
4
+ require 'mega/synchash'
4
5
 
5
6
  require 'glue/attribute'
6
- require 'glue/hash'
7
7
  require 'glue/flexob'
8
8
 
9
9
  # A Configuration holds a group of Settings organized by
@@ -20,7 +20,7 @@ class Configuration
20
20
  # TODO: find a better name.
21
21
  #++
22
22
 
23
- @@owners = Glue::SafeHash.new
23
+ @@owners = SyncHash.new
24
24
 
25
25
  # A datastructure to store Settings metadata.
26
26
 
@@ -107,7 +107,7 @@ class Configuration
107
107
  alias_method :[], :settings
108
108
 
109
109
  def method_missing(sym)
110
- if sym.to_s =~ /[A-Z]/ # facet's capitalized? is buggy at the moment.
110
+ if sym.to_s =~ /[A-Z]/ # nano's capitalized? is buggy at the moment.
111
111
  Flexob.new(self[constant(sym)])
112
112
  end
113
113
  end
@@ -1,6 +1,6 @@
1
- require 'facet/object/constant'
2
- require 'facet/string/underscore'
3
- require 'facet/string/demodulize'
1
+ require 'nano/object/constant'
2
+
3
+ require 'mega/orm_support'
4
4
 
5
5
  require 'glue/configuration'
6
6
  require 'glue/template'
@@ -63,7 +63,6 @@ class Fixture < Hash
63
63
 
64
64
  attr_accessor :objects
65
65
 
66
-
67
66
  def initialize(klass, options = { } )
68
67
  @klass = klass
69
68
  @name = class_to_name(klass)
@@ -1,6 +1,5 @@
1
- require 'facet/module/by_name'
1
+ require 'nano/module/by_name'
2
2
 
3
- require 'glue/object'
4
3
  require 'glue/attribute'
5
4
 
6
5
  module Glue
@@ -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 'facet/binding-of-caller'
46
+ require 'nano/binding/of_caller'
47
47
 
48
48
  Binding.of_caller do |b|
49
49
  value = b.eval(expr.to_str)
@@ -71,21 +71,57 @@ class Logger
71
71
  :inspect => :inspect, :to_yaml => :to_yaml
72
72
  )
73
73
 
74
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75
- # Global logger interface.
76
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74
+ # Dictate the way in which this logger should format the
75
+ # messages it displays. This method requires a block. The
76
+ # block should return formatted strings given severity,
77
+ # timestamp, msg, progname.
78
+ #
79
+ # Useless example:
80
+ #
81
+ # logger = Logger.new
82
+ # logger.format do |severity, timestamp, msg, progname|
83
+ # "#{progname}@#{timestamp} - #{severity}::#{msg}"
84
+ # end
85
+
86
+ def setup_format(&format_proc)
87
+ raise 'Formating block needed' unless format_proc
88
+ @format_proc = format_proc
89
+ end
77
90
 
78
- # Override the logger with your custom version.
91
+ private
79
92
 
80
- @@global_logger = Logger.new(STDERR)
93
+ # hackish use of *args, give me some love.
94
+
95
+ def format_message(*args)
96
+ @format_proc ? @format_proc.call(*args) : super(*args)
97
+ end
98
+
99
+ end
100
+
101
+ # Global logger interface. This provides an alternative
102
+ # Singleton interface to the Logger.
103
+
104
+ class Logger
81
105
 
106
+ SIMPLE_FORMAT = "%5s: %s\n"
107
+ @@global_logger = Logger.new(STDERR)
108
+ @@global_logger.setup_format do |severity, timestamp, msg, progname|
109
+ SIMPLE_FORMAT % [severity, msg]
110
+ end
111
+
82
112
  # Set the global Logger.
83
113
 
84
114
  def self.set(logger)
85
115
  if logger.is_a?(String)
86
116
  @@global_logger = Logger.new(logger)
117
+ @@global_logger.setup_format do |severity, timestamp, msg, progname|
118
+ SIMPLE_FORMAT % [severity, msg]
119
+ end
87
120
  elsif logger.is_a?(Logger)
88
121
  @@global_logger = logger
122
+ @@global_logger.setup_format do |severity, timestamp, msg, progname|
123
+ SIMPLE_FORMAT % [severity, msg]
124
+ end
89
125
  else
90
126
  raise ArgumentError.new
91
127
  end
@@ -119,7 +155,7 @@ class Logger
119
155
  unless expr.respond_to? :to_str
120
156
  warn "trace: Can't evaluate the given value: #{caller.first}"
121
157
  else
122
- require 'facet/binding-of-caller'
158
+ require 'nano/binding/of_caller'
123
159
 
124
160
  Binding.of_caller do |b|
125
161
  value = eval(expr.to_str, b)
@@ -139,22 +175,6 @@ class Logger
139
175
  end
140
176
  end
141
177
  end
142
-
143
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144
-
145
- private
146
-
147
- # the default Ruby logger has a hardwired silly format.
148
- # we use some Ruby magic to fix it!
149
-
150
- remove_const "Format"
151
-
152
- Format = "%5s: %s\n"
153
-
154
- def format_message(severity, timestamp, msg, progname)
155
- Format % [severity, msg]
156
- end
157
-
158
178
  end
159
179
 
160
180
  module Glue
@@ -0,0 +1,60 @@
1
+ require 'glue/flexob'
2
+
3
+ # WARNING: this is under construction, DON'T use yet.
4
+
5
+ module MetadataUtils
6
+ end
7
+
8
+ # Include this module to classes to add metadata/annotation
9
+ # functionality.
10
+
11
+ module MetadataMixin
12
+ def self.included(base)
13
+ base.module_eval do
14
+ @metadata = Flexob.new
15
+ @metadata[:self] = Flexob.new
16
+
17
+ class << self
18
+ def metadata
19
+ @metadata
20
+ end
21
+
22
+ def selmetadata=(md)
23
+ @metadata = md
24
+ end
25
+ end
26
+ end
27
+
28
+ =begin
29
+ case base
30
+ when Class:
31
+ base.module_eval do
32
+ def self.inherited(child)
33
+ MetadataUtils.enchant(child)
34
+ MetadataUtils.copy(self, child)
35
+ # gmosx: super must stay at the end.
36
+ super
37
+ end
38
+ end
39
+ when Module:
40
+ end
41
+ =end
42
+ end
43
+ end
44
+
45
+ class Module
46
+ # Annotate (define metadata) for the given symbol/class.
47
+
48
+ def ann(*args)
49
+ if args.first.is_a? Symbol
50
+ key = args.shift
51
+ else
52
+ key = :self
53
+ end
54
+ unless args.empty?
55
+ self.metadata[key] = Flexob.new(args.first)
56
+ end
57
+ end
58
+ end
59
+
60
+ # * George Moschovitis <gm@navel.r>
@@ -0,0 +1,40 @@
1
+ require 'ostruct'
2
+
3
+ # A simple mocking facility. Typically used in test cases.
4
+ #
5
+ # === Example:
6
+ #
7
+ # class ContextMock < Mock
8
+ # mock :response_headers, {}
9
+ # mock :host_url, 'http://www.nitrohq.com'
10
+ # end
11
+ #
12
+ # ctx = ContextMock.new
13
+ # ctx.response_headers['location'] = url
14
+ # ctx.host_url
15
+
16
+ class Mock < OpenStruct
17
+ class << self
18
+ attr :mocks
19
+
20
+ # Mock a symbol, val is the default values. Useful
21
+ # for mocking structured variables like arrays and
22
+ # hashes.
23
+
24
+ def mock(sym, val)
25
+ @mocks ||= {}
26
+ @mocks[sym] = val
27
+ attr_accessor sym
28
+ end
29
+ end
30
+
31
+ def initialize
32
+ super
33
+
34
+ for sym, val in self.class.mocks
35
+ unless val.is_a? Proc
36
+ instance_variable_set "@#{sym}", val
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,7 +1,10 @@
1
+ require 'mega/synchash'
2
+ require 'mega/syncarray'
3
+
4
+ require 'nano/time/change'
5
+
1
6
  require 'glue/attribute'
2
7
  require 'glue/flexob'
3
- require 'glue/array'
4
- require 'glue/hash'
5
8
 
6
9
  module Glue
7
10
 
@@ -49,11 +52,16 @@ class Property
49
52
  # You can use this mechanism to add your own, custom,
50
53
  # metadata.
51
54
 
52
- attr_accessor :meta
53
-
54
- def initialize(symbol, klass, meta = {})
55
+ attr_accessor :metadata
56
+
57
+ # Support legacy code, will be deprecated.
58
+
59
+ alias_method :meta, :metadata
60
+ alias_method :meta=, :metadata=
61
+
62
+ def initialize(symbol, klass, metadata = {})
55
63
  @symbol, @klass = symbol, klass
56
- @meta = meta
64
+ @metadata = metadata
57
65
  end
58
66
 
59
67
  def ==(other)
@@ -63,7 +71,6 @@ class Property
63
71
  def to_s
64
72
  return @symbol.to_s
65
73
  end
66
-
67
74
  end
68
75
 
69
76
  # A collection of Property related utility methods.
@@ -84,7 +91,7 @@ module PropertyUtils
84
91
  unless target.instance_variables.include?('@__props')
85
92
  # FIXME: should be thread safe here!
86
93
  target.instance_variable_set('@__meta', Flexob.new)
87
- target.instance_variable_set('@__props', SafeArray.new)
94
+ target.instance_variable_set('@__props', SyncArray.new)
88
95
 
89
96
  # gmosx: Ruby surprises and amazes me! We are in the Metaclass
90
97
  # when defining methods and attributes so @__props is really
@@ -201,7 +208,7 @@ module PropertyUtils
201
208
  # overrides.
202
209
 
203
210
  if prop.meta[:writer]
204
- target.module_eval %{
211
+ code = %{
205
212
  #{prop_setter(prop)}
206
213
 
207
214
  def __force_#{s}(val)
@@ -220,7 +227,24 @@ module PropertyUtils
220
227
  "val"
221
228
  end + %{)
222
229
  end
230
+
231
+ def __force_hash_#{s}(hash)
223
232
  }
233
+
234
+ case klass.name
235
+ when Time.name
236
+ code << %{
237
+ ihash = {}
238
+ hash = hash.map { |k, v| ihash[k.intern] = v.to_i }
239
+ @#{s} = @#{s}.change(ihash)
240
+ }
241
+ end
242
+
243
+ code << %{
244
+ end
245
+ }
246
+
247
+ target.module_eval(code)
224
248
  end
225
249
  end
226
250