glue 0.31.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/doc/AUTHORS +1 -1
  2. data/doc/LICENSE +2 -3
  3. data/doc/RELEASES +0 -4
  4. data/lib/glue.rb +3 -3
  5. data/lib/glue/attribute.rb +114 -0
  6. data/lib/glue/attributeutils.rb +117 -0
  7. data/lib/glue/autoreload.rb +0 -4
  8. data/lib/glue/builder.rb +0 -2
  9. data/lib/glue/builder/xml.rb +0 -2
  10. data/lib/glue/cache.rb +3 -5
  11. data/lib/glue/cache/drb.rb +0 -2
  12. data/lib/glue/cache/memory.rb +0 -2
  13. data/lib/glue/cache/og.rb +11 -6
  14. data/lib/glue/configuration.rb +60 -15
  15. data/lib/glue/fixture.rb +3 -5
  16. data/lib/glue/localization.rb +0 -2
  17. data/lib/glue/logger.rb +1 -2
  18. data/lib/glue/mail.rb +0 -2
  19. data/lib/glue/mailer.rb +4 -2
  20. data/lib/glue/mailer/incoming.rb +0 -2
  21. data/lib/glue/mailer/outgoing.rb +3 -5
  22. data/lib/glue/settings.rb +0 -2
  23. data/lib/glue/uri.rb +0 -2
  24. data/lib/glue/validation.rb +6 -8
  25. data/test/glue/builder/tc_xml.rb +3 -2
  26. data/test/glue/tc_attribute.rb +112 -0
  27. data/test/glue/{tc_property_mixins.rb → tc_attribute_mixins.rb} +9 -11
  28. data/test/glue/tc_configuration.rb +1 -1
  29. data/test/glue/tc_fixture.rb +4 -3
  30. data/test/glue/tc_logger.rb +2 -2
  31. data/test/glue/tc_mail.rb +22 -21
  32. data/test/glue/tc_stores.rb +0 -2
  33. data/test/glue/tc_uri.rb +12 -12
  34. data/test/glue/tc_validation.rb +13 -13
  35. metadata +52 -64
  36. data/INSTALL +0 -56
  37. data/ProjectInfo +0 -49
  38. data/README +0 -21
  39. data/lib/glue/markup.rb +0 -123
  40. data/lib/glue/property.rb +0 -290
  41. data/lib/glue/sanitize.rb +0 -48
  42. data/lib/glue/template.rb +0 -219
  43. data/setup.rb +0 -1585
  44. data/test/glue/tc_property.rb +0 -112
  45. data/test/glue/tc_property_type_checking.rb +0 -41
  46. data/test/glue/tc_template.rb +0 -35
data/lib/glue/fixture.rb CHANGED
@@ -3,7 +3,7 @@ require 'facet/kernel/constant'
3
3
  require 'facet/ormsupport'
4
4
 
5
5
  require 'glue/configuration'
6
- require 'glue/template'
6
+ require 'nitro/template'
7
7
 
8
8
  module Glue
9
9
 
@@ -94,7 +94,7 @@ class Fixture < Hash
94
94
  def parse_yaml(path)
95
95
  require 'yaml'
96
96
 
97
- str = Glue::Template.new.render(File.read(path))
97
+ str = Nitro::Template.new.render(File.read(path))
98
98
 
99
99
  if yaml = YAML::load(str)
100
100
  for name, data in yaml
@@ -116,7 +116,7 @@ class Fixture < Hash
116
116
  def parse_csv(path)
117
117
  require 'csv'
118
118
 
119
- str = Glue::Template.new.render(File.read(path))
119
+ str = Nitro::Template.new.render(File.read(path))
120
120
 
121
121
  reader = CSV::Reader.create(str)
122
122
  header = reader.shift
@@ -152,5 +152,3 @@ private
152
152
  end
153
153
 
154
154
  end
155
-
156
- # * George Moschovitis <gm@navel.gr>
@@ -127,5 +127,3 @@ module LocalizationAspect
127
127
  end
128
128
 
129
129
  end
130
-
131
- # * George Moschovitis <gm@navel.gr>
data/lib/glue/logger.rb CHANGED
@@ -157,6 +157,7 @@ class Logger
157
157
  # Saddly have to duplicate the code to make
158
158
  # Binding.of_caller work.
159
159
  #++
160
+
160
161
  def self.trace(expr, style=:p)
161
162
  unless expr.respond_to? :to_str
162
163
  warn "trace: Can't evaluate the given value: #{caller.first}"
@@ -207,5 +208,3 @@ module Logging
207
208
  end
208
209
 
209
210
  end
210
-
211
- # * George Moschovitis <gm@navel.gr>
data/lib/glue/mail.rb CHANGED
@@ -158,5 +158,3 @@ class Mail
158
158
  end
159
159
 
160
160
  end
161
-
162
- # * George Moschovitis <gm@navel.gr>
data/lib/glue/mailer.rb CHANGED
@@ -41,6 +41,10 @@ class Mailer < Mail
41
41
  # The default template root.
42
42
 
43
43
  setting :template_root, :default => 'template/mail', :doc => 'The default template root'
44
+
45
+ # The default from address
46
+
47
+ setting :from, :default => 'bot@nitroproject.org', :doc => 'The default from address'
44
48
 
45
49
  # An array to store the delivered mails, useful
46
50
  # for testing.
@@ -49,5 +53,3 @@ class Mailer < Mail
49
53
  end
50
54
 
51
55
  end
52
-
53
- # * George Moschovitis <gm@navel.gr>
@@ -39,5 +39,3 @@ module IncomingMailer
39
39
  end
40
40
 
41
41
  end
42
-
43
- # * George Moschovitis <gm@navel.gr>
@@ -9,7 +9,7 @@ module OutgoingMailer
9
9
 
10
10
  on_included %{ base.extend ClassMethods }
11
11
 
12
- def initialize(from = nil, to = nil, subject = nil, body = Glue::FileTemplate.new)
12
+ def initialize(from = nil, to = nil, subject = nil, body = Nitro::FileTemplate.new)
13
13
  super
14
14
  @charset = Mailer.default_charset.dup
15
15
  @encode_subject = Mailer.encode_subject
@@ -66,7 +66,7 @@ module OutgoingMailer
66
66
 
67
67
  mailer.send(method_name, *params)
68
68
 
69
- unless mailer.body.is_a?(String)
69
+ unless mailer.body.is_a? String
70
70
  mailer.body = render_body(method_name, mailer)
71
71
  end
72
72
 
@@ -94,7 +94,7 @@ module OutgoingMailer
94
94
  def perform_delivery_smtp(mail) # :nodoc:
95
95
  c = Mailer.server
96
96
  Net::SMTP.start(c[:address], c[:port], c[:domain], c[:username], c[:password], c[:authentication]) do |smtp|
97
- smtp.send_message(mail.encoded, mail.from, *[mail.to,mail.cc,mail.bcc].compact)
97
+ smtp.send_message(mail.encoded, mail.from, *[mail.to, mail.cc, mail.bcc].compact)
98
98
  end
99
99
  end
100
100
 
@@ -117,5 +117,3 @@ module OutgoingMailer
117
117
  end
118
118
 
119
119
  end
120
-
121
- # * George Moschovitis <gm@navel.gr>
data/lib/glue/settings.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  # Just an alias for glue/configuration.
2
2
 
3
3
  require 'glue/configuration'
4
-
5
- # * George Moschovitis <gm@navel.gr>
data/lib/glue/uri.rb CHANGED
@@ -188,5 +188,3 @@ end
188
188
 
189
189
  end
190
190
 
191
- # * George Moschovitis <gm@navel.gr>
192
-
@@ -1,4 +1,6 @@
1
1
  require 'facets/core/class/cattr'
2
+ require 'facets/core/module/on_included'
3
+ require 'facets/more/inheritor'
2
4
 
3
5
  require 'glue/configuration'
4
6
 
@@ -25,8 +27,8 @@ module Glue
25
27
  # === Example
26
28
  #
27
29
  # class User
28
- # prop_accessor :name, String
29
- # prop_accessor :level, Fixnum
30
+ # attr_accessor :name, String
31
+ # attr_accessor :level, Fixnum
30
32
  #
31
33
  # validate_length :name, :range => 2..6
32
34
  # validate_unique :name, :msg => :name_allready_exists
@@ -114,9 +116,9 @@ module Validation
114
116
  def clear
115
117
  @errors.clear
116
118
  end
117
-
119
+
118
120
  def to_a
119
- @errors.values
121
+ @errors.inject([]) { |a, kv| a << kv }
120
122
  end
121
123
 
122
124
  def join(glue)
@@ -443,7 +445,3 @@ end
443
445
  class Module # :nodoc: all
444
446
  include Glue::Validation::ClassMethods
445
447
  end
446
-
447
- # * George Moschovitis <gm@navel.gr>
448
- # * Brian Bugh <brian@xsi-design.com>
449
- # * Bryan Soto <bryan.a.soto@gmail.com>
@@ -1,4 +1,5 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'nitro', 'lib')
2
3
 
3
4
  require 'test/unit'
4
5
  require 'glue/builder/xml'
@@ -22,8 +23,8 @@ class TC_BuildersXml < Test::Unit::TestCase # :nodoc: all
22
23
  assert_equal '<b>This is bold</b>', x.buffer
23
24
 
24
25
  x = Glue::XmlBuilder.new
25
- x.a('Navel', :href => 'http://www.navel.gr')
26
- assert_equal '<a href="http://www.navel.gr">Navel</a>', x.buffer
26
+ x.a('Nitro', :href => 'http://www.nitroproject.org')
27
+ assert_equal '<a href="http://www.nitroproject.org">Nitro</a>', x.buffer
27
28
 
28
29
 
29
30
  x = Glue::XmlBuilder.new
@@ -0,0 +1,112 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'og', 'lib')
3
+
4
+ require 'test/unit'
5
+ require 'og'
6
+ require 'glue/logger'
7
+ require 'glue/attribute'
8
+
9
+ def VarChar(size)
10
+ return String, :sql => "VARCHAR(#{ size })"
11
+ end
12
+ NotNull = {:sql => "NOT NULL"}.freeze
13
+ Null = {:sql => "NULL"}.freeze
14
+
15
+ module Test # :nodoc: all
16
+
17
+ class Msg
18
+ include Og::Unmanageable
19
+
20
+ attr_accessor :owner_oid, Fixnum
21
+ attr_accessor :val1, :val2, :val3, Fixnum, :sql => "smallint"
22
+ attr_accessor :title, :body, String
23
+ attr_accessor :test, String, :sql => "char(10) NOT NULL"
24
+ attr_accessor :count, Fixnum
25
+ attr_accessor :create_time, Time
26
+
27
+ # a marshaled property
28
+ attr_accessor :options, Array
29
+
30
+ # property with macro arguments!
31
+ attr_accessor :address, VarChar(30), NotNull
32
+
33
+ def initialize
34
+ @create_time = Time.now
35
+ @options = []
36
+ end
37
+
38
+ end
39
+
40
+ class SubMsg < Msg
41
+ # to avoid conflicts with tc_og.rb
42
+ include Og::Unmanageable
43
+
44
+ # duplicate definition with different type!
45
+ attr_accessor :count, Float
46
+
47
+ # another property
48
+ attr_accessor :another, Fixnum
49
+ end
50
+
51
+ class C
52
+ attr_accessor :name
53
+ attr_accessor :description
54
+ end
55
+
56
+ class C
57
+ attr_accessor :name, String
58
+ attr_accessor :description, String
59
+ end
60
+
61
+ class TC_N_Attributes < Test::Unit::TestCase
62
+
63
+ def setup
64
+ Msg.define_force_methods
65
+ @msg1 = Msg.new
66
+ end
67
+
68
+ def teardown
69
+ @msg1 = nil
70
+ end
71
+
72
+ def test_props
73
+
74
+ # bug: props for subclasses.
75
+ # bug: props propagated to base classes.
76
+
77
+ assert(SubMsg.serializable_attributes)
78
+ assert_equal(Msg.serializable_attributes.size(), SubMsg.serializable_attributes.size() - 1)
79
+
80
+ assert_equal(11, Msg.serializable_attributes.size)
81
+ assert_equal(12, SubMsg.serializable_attributes.size)
82
+
83
+ # bug: duplicate definition
84
+
85
+ a = SubMsg.serializable_attributes.find { |p| :count == p }
86
+ assert_equal(Float, SubMsg.ann[SubMsg.serializable_attributes.find { |p| :count == p }].class)
87
+
88
+ # dont force conversion.
89
+
90
+ @msg1.count = 2.4
91
+ assert_equal(Float, @msg1.count.class)
92
+
93
+ # force conversion
94
+
95
+ @msg1.__force_count(2.4)
96
+ assert_equal(Fixnum, @msg1.count.class)
97
+ end
98
+
99
+ def test_macro_params
100
+ sql = Msg.ann[Msg.serializable_attributes.find { |p| :address == p}].sql
101
+ # FIXME: Temporarily dissabled.
102
+ # assert_equal 'VARCHAR(30) NOT NULL', sql
103
+ end
104
+
105
+
106
+ def test_soc
107
+ assert_equal String, C.ann.name.class
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -1,10 +1,11 @@
1
- $LOAD_PATH.unshift 'lib'
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'og', 'lib')
2
3
 
3
4
  require 'test/unit'
4
- require 'glue/property'
5
+ require 'glue/attribute'
5
6
 
6
7
  module Mixin
7
- prop_accessor :date
8
+ attr_accessor :date
8
9
  ann self, :dummy => [123]
9
10
  end
10
11
 
@@ -21,18 +22,18 @@ end
21
22
  class MixedWithProp
22
23
  include Mixin
23
24
 
24
- prop_accessor :dummy
25
+ attr_accessor :dummy
25
26
  end
26
27
 
27
28
  class Pure
28
- prop_accessor :dummy
29
+ attr_accessor :dummy
29
30
  end
30
31
 
31
32
  class Empty
32
33
  end
33
34
 
34
35
  class Base
35
- prop_accessor :date
36
+ attr_accessor :date
36
37
  ann self, :dummy => [123]
37
38
  end
38
39
 
@@ -52,7 +53,7 @@ class TC_MixinsTest < ::Test::Unit::TestCase
52
53
  end
53
54
 
54
55
  def test_manage_entities
55
- assert_respond_to( Pure, :properties )
56
+ assert_respond_to( Pure, :serializable_attributes )
56
57
  assert_respond_to( Pure.new, :dummy )
57
58
  end
58
59
 
@@ -61,7 +62,7 @@ class TC_MixinsTest < ::Test::Unit::TestCase
61
62
  end
62
63
 
63
64
  def test_managing_mixins
64
- assert_respond_to( Mixin, :properties )
65
+ assert_respond_to( Mixin, :serializable_attributes )
65
66
  end
66
67
 
67
68
  def test_managing_mixed_classes
@@ -83,6 +84,3 @@ class TC_MixinsTest < ::Test::Unit::TestCase
83
84
  =end
84
85
  end
85
86
  end
86
-
87
- # * Thomas Quas <tquas@yahoo.com>
88
- # * George Moschovitis <gm@navel.gr>
@@ -96,7 +96,7 @@ class TC_Configuration < Test::Unit::TestCase # :nodoc: all
96
96
  assert_equal '/gmosx/2', Configuration[Dummy][:root_dir].value
97
97
  assert_equal 2, Another.max_age
98
98
 
99
- Configuration.parse <<-end_val
99
+ Configuration.parse_yaml <<-end_val
100
100
  Another:
101
101
  max_age: 5
102
102
  TC_Configuration.Internal:
@@ -1,4 +1,5 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'nitro', 'lib')
2
3
 
3
4
  require 'test/unit'
4
5
  require 'glue/fixture'
@@ -27,8 +28,8 @@ class TestFixtureExplicitRootDir < Test::Unit::TestCase # :nodoc: all
27
28
  assert_equal 'Renos', users['renos'].name
28
29
 
29
30
  articles = Fixture.new(Article, :root_dir => RootDir)
30
-
31
- assert_equal 9, articles.size
31
+
32
+ assert_equal 10, articles.size
32
33
  assert_equal 'This is cool', articles['article_1'].title
33
34
  assert_equal 'Another', articles['article_2'].title
34
35
  assert_equal 'I love this', articles['Test'].title
@@ -80,7 +81,7 @@ class TestFixtureRootDirSetting < Test::Unit::TestCase # :nodoc: all
80
81
 
81
82
  articles = Fixture.new(Article)
82
83
 
83
- assert_equal 9, articles.size
84
+ assert_equal 10, articles.size
84
85
  assert_equal 'This is cool', articles['article_1'].title
85
86
  assert_equal 'Another', articles['article_2'].title
86
87
  assert_equal 'I love this', articles['Test'].title
@@ -20,8 +20,8 @@ class TC_Logger < Test::Unit::TestCase # :nodoc: all
20
20
  # bug: Binding.of_caller thinks Logger is the caller.
21
21
  a = 14
22
22
  b = 13
23
- Logger.trace 'a * b'
24
- assert_equal(" INFO: hello\nDEBUG: a * b = 182\n", @io.string)
23
+ # Logger.trace 'a * b'
24
+ # assert_equal(" INFO: hello\nDEBUG: a * b = 182\n", @io.string)
25
25
 
26
26
  @io.string = ''
27
27
  Logger.debug 'hello'
data/test/glue/tc_mail.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'nitro', 'lib')
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'og', 'lib')
2
4
 
3
5
  $NITRO_NO_ENVIRONMENT = true
4
6
 
5
7
  require 'test/unit'
6
8
  require 'ostruct'
7
-
8
9
  require 'nitro'
9
10
  require 'glue/configuration'
10
11
  require 'glue/mailer'
@@ -15,24 +16,24 @@ class TestCaseMail < Test::Unit::TestCase # :nodoc: all
15
16
  class DummyMailer < Mailer
16
17
  def initialize
17
18
  super
18
- @bcc = 'gm@navel.gr'
19
+ @bcc = 'george.moschovitis@gmail.com'
19
20
  @template_root = 'test/public/dummy_mailer'
20
21
  end
21
22
 
22
23
  def registration(to, username, token)
23
24
  @to = to
24
- @from = 'system@navel.gr'
25
+ @from = 'system@nitroproject.org'
25
26
  @subject = 'Nitro.com registration'
26
- @cc = 'gm@navel.gr'
27
+ @cc = 'george.moschovitis@gmail.com'
27
28
  @body.username = username
28
29
  @body.token = token
29
30
  end
30
31
 
31
32
  def greek(to)
32
33
  @to = to
33
- @from = 'system@navel.gr'
34
+ @from = 'system@nitroproject.org'
34
35
  @subject = 'Ελληνικός Τίτλος'
35
- @cc = 'gm@navel.gr'
36
+ @cc = 'george.moschovitis@gmail.com'
36
37
  @body = 'Τί έγινε ρε παιδιά;'
37
38
  end
38
39
  end
@@ -42,22 +43,22 @@ class TestCaseMail < Test::Unit::TestCase # :nodoc: all
42
43
 
43
44
  def register
44
45
  token = 999
45
- deliver_registration('gmosx@navel.gr', 'gmosx', token)
46
+ deliver_registration('gmosx@nitroproject.org', 'gmosx', token)
46
47
  end
47
48
  end
48
49
  =end
49
50
  def test_mail
50
- m = Glue::Mail.new 'gmosx@navel.gr', 'drak@navel.gr', 'A simple test', 'This is the body of the message'
51
- expected = %{From: gmosx@navel.gr
52
- To: drak@navel.gr
51
+ m = Glue::Mail.new 'gmosx@nitroproject.org', 'drak@nitroproject.org', 'A simple test', 'This is the body of the message'
52
+ expected = %{From: gmosx@nitroproject.org
53
+ To: drak@nitroproject.org
53
54
  Subject: A simple test
54
55
 
55
56
  This is the body of the message}
56
57
  assert_equal expected, m.encoded
57
58
 
58
- m.to = %w{ renos@navel.gr stella@navel.gr }
59
- expected = %{From: gmosx@navel.gr
60
- To: renos@navel.gr, stella@navel.gr
59
+ m.to = %w{ renos@nitroproject.org stella@nitroproject.org }
60
+ expected = %{From: gmosx@nitroproject.org
61
+ To: renos@nitroproject.org, stella@nitroproject.org
61
62
  Subject: A simple test
62
63
 
63
64
  This is the body of the message}
@@ -68,19 +69,19 @@ This is the body of the message}
68
69
  def test_mailer
69
70
  assert_equal 0, DummyMailer.deliveries.size
70
71
 
71
- Mailer.server[:address] = 'mail.navel.gr'
72
- # assert_equal 'mail.navel.gr', DummyMailer.server[:address]
72
+ Mailer.server[:address] = 'mail.nitroproject.org'
73
+ # assert_equal 'mail.nitroproject.org', DummyMailer.server[:address]
73
74
 
74
75
  Mailer.delivery_method = :test
75
76
  Mailer.template_root = File.join(File.dirname(__FILE__), '..', 'root', 'dummy_mailer')
76
77
  token = 999
77
- DummyMailer.deliver_registration('gm@navel.gr', 'gmosx', token)
78
+ DummyMailer.deliver_registration('george.moschovitis@gmail.com', 'gmosx', token)
78
79
  assert_equal 1, DummyMailer.deliveries.size
79
80
 
80
- expected = %{From: system@navel.gr
81
- To: gm@navel.gr
82
- Cc: gm@navel.gr
83
- Bcc: gm@navel.gr
81
+ expected = %{From: system@nitroproject.org
82
+ To: george.moschovitis@gmail.com
83
+ Cc: george.moschovitis@gmail.com
84
+ Bcc: george.moschovitis@gmail.com
84
85
  Subject: =?utf-8?Q?Nitro=2ecom_registration?=
85
86
 
86
87
  Hello gmosx
@@ -91,7 +92,7 @@ Here is your <b>Token</b>: 999
91
92
  }
92
93
  assert_equal expected, DummyMailer.deliveries[0].encoded
93
94
 
94
- DummyMailer.deliver_greek('gm@navel.gr')
95
+ DummyMailer.deliver_greek('george.moschovitis@gmail.com')
95
96
  assert_equal 2, DummyMailer.deliveries.size
96
97
  end
97
98
  =end