glue 0.29.0 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
data/ProjectInfo CHANGED
@@ -2,40 +2,38 @@
2
2
 
3
3
  TITLE : &title Glue
4
4
  NAME : &pkg glue
5
- VERSION : '0.29.0'
5
+ VERSION : '0.30.0'
6
6
  STATUS : beta
7
7
 
8
8
  AUTHOR : George Moschovitis
9
9
  EMAIL : &email gm@navel.gr
10
- HOMEPAGE : "http://www.nitrohq.com"
10
+ HOMEPAGE : "http://www.nitroproject.org"
11
11
 
12
12
  SUMMARY: Utility methods and classes for Nitro.
13
13
 
14
14
  DESCRIPTION: >
15
15
  Utility methods and classes for Nitro.
16
16
 
17
- DEPENDENCIES:
18
- - [ facets, '= 1.0.3' ]
19
- - [ cmdparse, '= 2.0.0' ]
20
-
21
- DISTRIBUTE: [ gem, tgz, zip ]
22
-
23
17
  RUBYFORGE:
24
18
  PROJECT: 'nitro'
25
19
  USERNAME: 'gmosx'
26
20
 
27
- RDOC:
28
- - dir: rdoc
29
- options: ['--all', '--inline-source']
30
- include:
31
- - 'lib/glue/**/*'
32
- - '[A-Z]*'
21
+ DEPENDENCIES:
22
+ - [ facets, '= 1.3.3' ]
23
+
24
+ PACKAGE: !!package
25
+ distribute: [ gem, tgz, zip ]
26
+
27
+ RDOC: !!rdoc
28
+ dir: rdoc
29
+ options: ['--all', '--inline-source']
30
+ include:
31
+ - 'lib/glue/**/*'
32
+ - '[A-Z]*'
33
33
 
34
- # Anything to require upfront?
35
- #TEST:
36
- # fixture: ''
34
+ TEST: !!test
37
35
 
38
- ANNOUNCE:
36
+ ANNOUNCE: !!announce
39
37
  to: george.moschovitis@gmail.com
40
38
  from: gm@navel.gr
41
39
  domain: navel.gr
@@ -47,15 +45,5 @@ ANNOUNCE:
47
45
  file: ANN
48
46
  slogan: Glue
49
47
  links:
50
- - http://www.nitrohq.com
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
48
+ - http://www.nitroproject.org
61
49
 
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Glue 0.29.0 README
1
+ = Glue 0.30.0 README
2
2
 
3
3
  Useful utilites and methods.
4
4
 
@@ -6,7 +6,7 @@ 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 Nano/Mega
9
+ graduate smaller libraries to the more general Facets
10
10
  ruby project.
11
11
 
12
12
 
data/doc/RELEASES CHANGED
@@ -1,3 +1,11 @@
1
+ == Version 0.30.0
2
+
3
+ Cleaned up the codebase. Removed files duplicating functionality
4
+ already present in Facets. Moreover, we moved several generally
5
+ useful files into Facets. Expect the cleanup process to be
6
+ continued in next versions.
7
+
8
+
1
9
  == Version 0.29.0
2
10
 
3
11
  * MemCache store for the generalized caching system.
data/lib/glue.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # = Glue
2
2
  #
3
- # Copyright (c) 2004-2005, Navel Ltd (http://www.navel.gr)
4
- # Copyright (c) 2004-2005, George Moschovitis (http://www.gmosx.com)
3
+ # Copyright (c) 2004-2006, George Moschovitis (http://www.gmosx.com)
4
+ # Copyright (c) 2004-2006, Navel Ltd (http://www.navel.gr)
5
5
  #
6
- # Glue (http://www.nitrohq.com) is copyrighted free software
6
+ # Glue (http://www.nitroproject.org) is copyrighted free software
7
7
  # created and maintained by George Moschovitis (mailto:gm@navel.gr)
8
8
  # and released under the standard BSD Licence. For details
9
9
  # consult the file doc/LICENCE.
@@ -12,7 +12,7 @@ require 'English'
12
12
  require 'pp'
13
13
 
14
14
  require 'facet/nullclass'
15
- require 'glue/paramix' # keep this before module/is
15
+ require 'facets/more/paramix' # keep this before module/is
16
16
  require 'facet/module/is'
17
17
 
18
18
  require 'glue/property'
@@ -36,7 +36,7 @@ module Glue
36
36
 
37
37
  # The version.
38
38
 
39
- Version = '0.29.0'
39
+ Version = '0.30.0'
40
40
 
41
41
  # Library path.
42
42
 
@@ -33,7 +33,7 @@ module Kernel
33
33
  $autoreload_dirty = true
34
34
  need_reload.each_pair do |file,mtime|
35
35
  file_mtime[file] = mtime
36
- Logger.debug "File '#{ file }' reloaded"
36
+ Logger.debug "File '#{ file }' reloaded" if $DBG
37
37
  begin
38
38
  load(file)
39
39
  rescue Exception => e
@@ -48,7 +48,7 @@ module Kernel
48
48
  if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
49
49
  $autoreload_dirty = true
50
50
  file_mtime[file] = mtime
51
- Logger.debug "File '#{ file }' changed"
51
+ Logger.debug "File '#{ file }' changed" if $DBG
52
52
  end
53
53
  end
54
54
 
data/lib/glue/builder.rb CHANGED
@@ -32,17 +32,28 @@ class Builder
32
32
 
33
33
  # Provide the target where the builder output will be
34
34
  # accomulated. The builder utilizes duck typing to make it
35
- # compatible with anly target responding to <<.
35
+ # compatible with any target responding to <<.
36
36
 
37
- def initialize(buffer = '', *modules)
38
- @buffer = buffer
39
-
37
+ def initialize(buffer = '', options = {})
38
+ @buffer = buffer
40
39
  end
41
40
 
41
+ # Emit a text string.
42
+
43
+ def text!(str)
44
+ @buffer << str
45
+
46
+ return self
47
+ end
48
+ alias_method :print, :text!
49
+ alias_method :<<, :text!
50
+
51
+ def to_s
52
+ @buffer.to_s
53
+ end
54
+
42
55
  end
43
56
 
44
57
  end
45
58
 
46
59
  # * George Moschovitis <gm@navel.gr>
47
-
48
- __END__
@@ -1,9 +1,5 @@
1
1
  require 'glue/builder'
2
2
 
3
- require 'nitro/helper/xhtml'
4
- require 'nitro/helper/form'
5
- require 'nitro/helper/table'
6
-
7
3
  module Glue
8
4
 
9
5
  # A Builder for programmatically building XML blocks.
@@ -12,6 +8,10 @@ module Glue
12
8
  #++
13
9
 
14
10
  class XmlBuilder < Builder
11
+ require 'nitro/helper/xhtml'
12
+ require 'nitro/helper/form'
13
+ require 'nitro/helper/table'
14
+
15
15
  include_builder Nitro::XhtmlHelper
16
16
  include_builder Nitro::TableHelper
17
17
  include_builder Nitro::FormHelper
@@ -73,15 +73,6 @@ class XmlBuilder < Builder
73
73
  return self
74
74
  end
75
75
 
76
- # Emit a text string.
77
-
78
- def text!(str)
79
- @buffer << str
80
-
81
- return self
82
- end
83
- alias_method :print, :text!
84
-
85
76
  # Emit a comment.
86
77
 
87
78
  def comment!(str)
@@ -33,7 +33,6 @@ class DrbCache < MemoryCache
33
33
  # :address = The address of the DRb cache object.
34
34
  # :port = The port of the DRb cache object.
35
35
 
36
-
37
36
  # The address of the Session cache / store (if distibuted).
38
37
 
39
38
  setting :address, :default => '127.0.0.1', :doc => 'The address of the Session cache'
@@ -43,8 +42,8 @@ class DrbCache < MemoryCache
43
42
  setting :port, :default => 9069, :doc => 'The port of the Session cache'
44
43
 
45
44
 
46
- def initialize
47
- @hash = DRbObject.new(nil, "druby://#{DrbCache.address}:#{DrbCache.port}")
45
+ def initialize(address = DrbCache.address, port = DrbCache.port)
46
+ @hash = DRbObject.new(nil, "druby://#{address}:#{port}")
48
47
  end
49
48
 
50
49
  end
@@ -51,16 +51,16 @@ module Glue
51
51
 
52
52
  def decode_file(fn)
53
53
  val = nil
54
- File.open(fn,"r") do |f|
54
+ File.open(fn,"rb") do |f|
55
55
  f.flock(File::LOCK_EX)
56
- val = Marshal.load( File.read(fn) )
56
+ val = Marshal.load( f.read )
57
57
  f.flock(File::LOCK_UN)
58
58
  end
59
59
  return val
60
60
  end
61
61
 
62
62
  def encode_file(fn, value)
63
- File.open(fn, "w") do |f|
63
+ File.open(fn, "wb") do |f|
64
64
  f.flock(File::LOCK_EX)
65
65
  f.chmod(0600)
66
66
  f.write(Marshal.dump(value))
@@ -2,6 +2,8 @@ require 'yaml'
2
2
 
3
3
  require 'facet/kernel/constant'
4
4
  require 'facet/synchash'
5
+ require 'facet/dictionary'
6
+ require 'facet/string/capitalized'
5
7
 
6
8
  require 'glue/attribute'
7
9
  require 'glue/flexob'
@@ -9,7 +11,13 @@ require 'glue/flexob'
9
11
  module Glue
10
12
 
11
13
  # A Configuration holds a group of Settings organized by
12
- # Owners.
14
+ # Owners. An owner is a class that represents the system to be
15
+ # configured. An alias for this class is Settings.
16
+ #
17
+ # You can pass strings, constants or symbols as keys for the
18
+ # classes to be configured. Passing symbols you can configure
19
+ # classes even before they are defined.
20
+ #
13
21
  #--
14
22
  # TODO: implement with annotations.
15
23
  #++
@@ -25,49 +33,86 @@ class Configuration
25
33
  @@owners = SyncHash.new
26
34
 
27
35
  # A datastructure to store Settings metadata.
28
-
36
+ #
37
+ # Please note the difference between :default and :value,
38
+ # :default does NOT override :value.
39
+
29
40
  class Setting
30
41
  attr_accessor :owner, :name, :type, :value, :options
31
42
 
32
43
  def initialize(owner, name, options)
33
- raise ArgumentError.new('A default value is required') unless options.key?(:default)
44
+ if options.key? :value
45
+ @value = options[:value]
46
+ elsif options.key? :default
47
+ @value = options[:default]
48
+ else
49
+ raise ArgumentError.new('A value is required')
50
+ end
51
+
34
52
  @owner, @name = owner, name
35
- @options = options
36
- @value = options[:default]
53
+ @options = options
37
54
  @type = options[:type] = options[:type] || @value.class
38
55
  end
39
56
 
40
- def value=(value)
41
- @value = value
42
- constant(@owner).module_eval %{
43
- @@#{@name} = #{value.inspect}
44
- }
45
- end
57
+ # Update the setting from an options hash. The update does
58
+ # NOT take default values into account!
59
+
60
+ def update(hash)
61
+ if hash.key? :value
62
+ @value = hash[:value]
63
+ @type = @value.class
64
+ end
65
+
66
+ if hash.key? :type
67
+ @type = hash[:type]
68
+ end
46
69
 
70
+ @options.update(hash)
71
+ end
72
+
73
+ # Text representation of this setting.
74
+
47
75
  def to_s
48
76
  @value.to_s
49
77
  end
50
78
 
51
79
  end
80
+
81
+ # A collection of Settings. This helper enables intuitive
82
+ # settings initialization like this:
83
+ #
84
+ # Configuration.Compiler.template_root = 'public'
85
+ # instead of
86
+ # Configuration.setting :compiler, :template_root, :value => 'public'
52
87
 
88
+ class SettingCollection < Hash
89
+ attr_accessor :owner
90
+
91
+ # Handles setting readers and writers.
92
+
93
+ def method_missing(sym, *args)
94
+ if sym.to_s =~ /=$/
95
+ # Remove trailing
96
+ sym = sym.to_s.gsub(/=/, '').to_sym
97
+ Configuration.setting @owner, sym, :value => args.first
98
+ else
99
+ self[sym]
100
+ end
101
+ end
102
+ end
103
+
53
104
  class << self
54
105
 
55
- # Inject the configuration parameters to configuration
56
- # classes.
106
+ # Inject the configuration parameters provided as a hash
107
+ # (dictionary, ordered) to classes to be configured.
108
+ #
109
+ # === Warning: Pass an ordered hash (dictionary)
57
110
 
58
111
  def setup(options)
59
112
  options.each do |owner, ss|
60
113
  next unless ss
61
- begin
62
- owner = constant(owner)
63
- rescue NameError
64
- next
65
- end
66
114
  ss.each do |name, s|
67
- @@owners[owner][name.to_sym].value = s
68
- owner.module_eval %{
69
- @@#{name} = #{s.inspect}
70
- }
115
+ add_setting(owner, name.to_sym, :value => s)
71
116
  end
72
117
  end
73
118
  end
@@ -76,14 +121,15 @@ class Configuration
76
121
 
77
122
  def parse(options)
78
123
  temp = YAML::load(options)
79
- options = {}
124
+ options = Dictionary.new
80
125
  temp.each do |k, v|
81
126
  begin
82
- options[constant(k.gsub(/\./, '::').to_sym)] = v
127
+ options[k.gsub(/\./, '::').to_sym] = v
83
128
  rescue Object
84
129
  options[k] = v
85
130
  end
86
131
  end
132
+
87
133
  setup(options)
88
134
  end
89
135
 
@@ -92,15 +138,38 @@ class Configuration
92
138
  def load(filename)
93
139
  parse(File.read(filename))
94
140
  end
95
-
141
+
142
+ # Manually add a configuration setting. The class key can
143
+ # be the actual class name constant or a symbol. If the
144
+ # setting is already defined it updates it.
145
+ #
146
+ # === Examples
147
+ #
148
+ # Configuration.add_setting Compiler, :verification, :value => 12, :doc => '...'
149
+ # Configuration.setting :IdPart, :verify_registration_email, :value => false
150
+ # s = Configuration.Compiler.verification.value
151
+
96
152
  def add_setting(owner, name, options)
97
- s = @@owners[owner] || {}
98
- s[name] = Setting.new(owner, name, options)
99
- @@owners[owner] = s
153
+ owner = owner.to_s.to_sym
154
+ @@owners[owner] ||= {}
155
+ if s = @@owners[owner][name]
156
+ # The setting already exists, update it.
157
+ s.update(options)
158
+ else
159
+ # The setting does not exist, create it.
160
+ @@owners[owner][name] = Setting.new(owner, name, options)
161
+ end
100
162
  end
101
-
163
+ alias_method :setting, :add_setting
164
+
165
+ # Return the settings for the given owner. The owner is
166
+ # typically the Class that represents the system to be
167
+ # configured. If no class is provided, it returns all the
168
+ # registered settings.
169
+
102
170
  def settings(owner = nil)
103
171
  if owner
172
+ owner = owner.to_s.to_sym
104
173
  @@owners[owner]
105
174
  else
106
175
  @@owners.values.inject([]) { |memo, obj| memo.concat(obj.values) }
@@ -109,9 +178,20 @@ class Configuration
109
178
  alias_method :all, :settings
110
179
  alias_method :[], :settings
111
180
 
181
+
182
+ #--
183
+ # FIXME: this does not work as expected.
184
+ #++
185
+
112
186
  def method_missing(sym)
113
- if sym.to_s =~ /[A-Z]/ # FIXME: facets's capitalized? is buggy at the moment.
114
- Flexob.new(self[constant(sym)])
187
+ if sym.to_s.capitalized?
188
+ # Flexob.new(self[sym])
189
+ bdl = SettingCollection.new
190
+ bdl.owner = sym
191
+ if hash = self[sym]
192
+ bdl.update(hash)
193
+ end
194
+ return bdl
115
195
  end
116
196
  end
117
197
  end
@@ -126,24 +206,28 @@ end
126
206
 
127
207
  class Module
128
208
 
129
- # Defines a configuration setting.
130
- #--
131
- # TODO: implement with annotations.
132
- #++
209
+ # Defines a configuration setting for the enclosing class.
210
+ #
211
+ # === Example
212
+ #
213
+ # class Compiler
214
+ # setting :template_root, :default => 'src/template', :doc => 'The template root dir'
215
+ # end
133
216
 
134
217
  def setting(sym, options = {})
135
218
  Glue::Configuration.add_setting(self, sym, options)
219
+
136
220
  module_eval %{
137
- mattr_accessor sym, options[:default]
221
+ def self.#{sym}
222
+ Glue::Configuration[#{self}][:#{sym}].value
223
+ end
138
224
 
139
- def self.#{sym.id2name}=(obj)
140
- @@#{sym.id2name} = obj
141
- Glue::Configuration[#{self}][:#{sym}].value = obj
225
+ def self.#{sym}=(obj)
226
+ Glue::Configuration.setting #{self}, :#{sym}, :value => obj
142
227
  end
143
228
  }
144
229
  end
145
230
 
146
231
  end
147
232
 
148
-
149
233
  # * George Moschovitis <gm@navel.gr>