glue 0.0.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,19 @@
1
+ 17-03-2005 George Moschovitis <gm@navel.gr>
2
+
3
+ * Rakefile: updated and fixed bugs.
4
+
5
+ * test/*: changes to make the tests pass again.
6
+
7
+ 12-03-2005 George Moschovitis <gm@navel.gr>
8
+
9
+ * test/glue/tc_validation.rb: added more tests.
10
+
11
+ * lib/glue/validation.rb (#validate_numeric): implemented,
12
+
13
+ 10-03-2005 George Moschovitis <gm@navel.gr>
14
+
15
+ * lib/glue.rb: added Version.
16
+
17
+ * Rakefile: implemented.
18
+
19
+ * split from nitro CHANGELOG.
data/INSTALL ADDED
@@ -0,0 +1,56 @@
1
+ = Instalation with RubyGems
2
+
3
+ 1. Download and install RubyGems:
4
+
5
+ http://rubygems.rubyforge.org
6
+
7
+ 2. Install the distribution:
8
+
9
+ gem install glue
10
+
11
+ When asked about the dependencies to include, only accept
12
+ the dependencies for the RDBMS backends you are planning
13
+ to use.
14
+
15
+ 3. Set environment variable (required to load RubyGems):
16
+
17
+ export RUBYOPT=-rubygems
18
+
19
+ You can add this in you .bashrc in Unix.
20
+
21
+ Alternatively you can run your applications with the -rubygem
22
+ option:
23
+
24
+ ruby -rubygem xxx.rb
25
+
26
+ = Installation without RubyGems using script.
27
+
28
+ Installation without RubyGems is *strongly* discouraged.
29
+ However, as Glue is all about freedom and possibilities,
30
+ a standard installation script is provided.
31
+
32
+ 1. Switch to an administrator account
33
+
34
+ For example in Unix:
35
+
36
+ $ su -
37
+
38
+ 2. Run the installation script.
39
+
40
+ $ ruby install.rb
41
+
42
+ This installation script also installs some vendor libraries
43
+ that you possibly have allready installed. Use with caution.
44
+
45
+ = Manual installation.
46
+
47
+ Uncompress your distribution (Unix example):
48
+
49
+ $ cd my_dir
50
+ $ tar xvfz glue-x.x.x.tar.gz
51
+
52
+ Put the libray dir in the Ruby path (Unix example):
53
+
54
+ $ export RUBYOPT='-I path/to/glue/lib'
55
+
56
+
data/README ADDED
@@ -0,0 +1,3 @@
1
+ = Glue
2
+
3
+ Useful utilites and methods.
data/Rakefile CHANGED
@@ -1,14 +1,77 @@
1
- # -*- ruby -*-
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
+ # $Id$
2
4
 
3
- require 'rubygems'
4
- require 'hoe'
5
- require './lib/glue.rb'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+ require 'rake/gempackagetask'
6
8
 
7
- Hoe.new('glue', Glue::VERSION) do |p|
8
- p.developer('Jordan Dobson', 'jordan.dobson@madebysquad.com')
9
- p.extra_deps = ['mechanize']
10
- p.extra_deps = ['httparty']
11
- p.extra_dev_deps = ['mocha']
9
+ task :default => :package
10
+
11
+ # Run all tests.
12
+
13
+ Rake::TestTask.new(:test_all) do |t|
14
+ t.libs << 'test'
15
+ t.test_files = FileList['test/**/tc*.rb']
16
+ t.verbose = true
17
+ end
18
+
19
+ # Generate RDoc documentation.
20
+
21
+ Rake::RDocTask.new do |rd|
22
+ rd.main = 'README'
23
+ rd.rdoc_dir = 'doc/rdoc'
24
+ rd.rdoc_files.include('README', 'INSTALL', 'lib/**/*.rb')
25
+ rd.options << '--all --inline-source'
26
+ end
27
+
28
+ # Build gem.
29
+
30
+ spec = Gem::Specification.new do |s|
31
+ s.name = 'glue'
32
+ if File.read('lib/glue.rb') =~ /Version\s+=\s+'(\d+\.\d+\.\d+)'/
33
+ s.version = $1
34
+ else
35
+ raise 'No version found'
36
+ end
37
+ s.summary = 'Glue utilities'
38
+ s.description = 'A collection of utilities and useful classes'
39
+ s.add_dependency 'extensions', '>= 0.5'
40
+ s.add_dependency 'flexmock', '>= 0.0.3'
41
+
42
+ s.required_ruby_version = '>= 1.8.1'
43
+
44
+ s.files = FileList[
45
+ '[A-Z]*', 'install.rb', '{doc,lib,test,vendor}/**/*'
46
+ ].exclude('.svn/**/*').exclude('**/*.log').to_a
47
+
48
+ s.require_path = 'lib'
49
+ s.autorequire = 'glue'
50
+
51
+ s.has_rdoc = true
52
+ s.extra_rdoc_files = FileList['[A-Z]*'].exclude('*.og').to_a
53
+ s.rdoc_options << '--main' << 'README' << '--title' << 'Glue Documentation'
54
+ s.rdoc_options << '--all' << '--inline-source'
55
+
56
+ s.test_files = []
57
+
58
+ s.bindir = 'bin'
59
+
60
+ s.author = 'George Moschovitis'
61
+ s.email = 'gm@navel.gr'
62
+ s.homepage = 'http://nitro.rubyforge.org'
63
+ s.rubyforge_project = 'nitro'
64
+ end
65
+
66
+ Rake::GemPackageTask.new(spec) do |pkg|
67
+ pkg.package_dir = 'dist'
68
+ pkg.need_zip = true
69
+ pkg.need_tar = true
70
+ end
71
+
72
+ # Manual install (not recommended).
73
+
74
+ task :install do
75
+ ruby 'install.rb'
12
76
  end
13
77
 
14
- # vim: syntax=Ruby
data/doc/AUTHORS ADDED
@@ -0,0 +1,16 @@
1
+ MAIN DEVELOPER:
2
+
3
+ * George Moschovitis <gm@navel.gr>
4
+ Project leader, architecture and design, code,
5
+ documentation, maintainer.
6
+
7
+ IDEAS, ADDITIONAL CODING, SUPPORT:
8
+
9
+ * Michael Neumann <mneumann@ntecs.de>
10
+ Design, additional coding and bug reports.
11
+
12
+ * Gavin Sinclair <gsinclair@soyabean.com.au>
13
+ Logger#trace method.
14
+
15
+ * Thomas Quas <tquas@yahoo.com>
16
+ Ideas, bug reports, unit tests.
data/doc/LICENSE ADDED
@@ -0,0 +1,33 @@
1
+ The BSD License
2
+
3
+ Copyright (c) 2004-2005, George 'tml' Moschovitis.
4
+ Copyright (c) 2004-2005, Navel Ltd. (http://www.navel.gr)
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are
9
+ met:
10
+
11
+ * Redistributions of source code must retain the above copyright
12
+ notice, this list of conditions and the following disclaimer.
13
+
14
+ * Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+
18
+ * Neither the name of Navel nor the names of its contributors may be
19
+ used to endorse or promote products derived from this software
20
+ without specific prior written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+
data/doc/RELEASES ADDED
@@ -0,0 +1,5 @@
1
+ == Version 0.13.0 was released on 17/03/2005.
2
+
3
+ The first release as a standalone gem.
4
+
5
+ * Additional validations.
data/install.rb ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # * George Moschovitis <gm@navel.gr>
4
+ # (c) 2004-2005 Navel, all rights reserved.
5
+ # $Id$
6
+
7
+ require 'rbconfig'
8
+ require 'ftools'
9
+
10
+ dst_dir = Config::CONFIG['sitelibdir']
11
+
12
+ Dir.chdir('lib') do
13
+ Dir['**/*.rb'].each do |file|
14
+ File.mkpath File.join(dst_dir, File.dirname(file)), true
15
+ File.install file, File.join(dst_dir, file), 0644, true
16
+ end
17
+ end
18
+
19
+ # gmosx: this is potentially dangerous, rethink.
20
+
21
+ Dir.chdir('vendor') do
22
+ Dir['**/*.rb'].each do |file|
23
+ File.mkpath File.join(dst_dir, File.dirname(file)), true
24
+ File.install file, File.join(dst_dir, file), 0644, true
25
+ end
26
+ end
27
+
28
+ puts %{
29
+
30
+
31
+ ---
32
+ Congratulations, you have successfully installed Og!
33
+ The libraries where installed in '#{dst_dir}'.
34
+
35
+ You probably need to install the Glue library
36
+ as well. (http://nitro.rubyforge.org)
37
+
38
+ To verify that everything works correctly, try to run an
39
+ example by issuing:
40
+
41
+ $ cd examples
42
+ $ ruby run.rb
43
+
44
+ at the command line.
45
+
46
+ Enjoy the magic of Og!
47
+ }
data/lib/glue.rb CHANGED
@@ -1,64 +1,62 @@
1
- require 'rubygems'
2
- require 'httparty'
3
- require 'nokogiri'
4
- require 'open-uri'
1
+ # = Glue
2
+ #
3
+ # General libraries used by various projects.
4
+ #
5
+ # George Moschovitis <gm@navel.gr>
6
+ # (c) 2004-2005 Navel, all rights reserved.
7
+ # $Id: glue.rb 300 2005-03-16 13:23:10Z gmosx $
8
+
9
+ require 'English'
10
+ require 'pp'
11
+
12
+ require 'glue/property'
13
+ require 'glue/attribute'
14
+
15
+ # The standard namespace module.
16
+
17
+ module N; end
18
+
19
+ class NilClass
20
+
21
+ # quite usefull for error tolerant apps.
22
+ # a bit dangerous? Will have to rethink this.
23
+
24
+ def empty?
25
+ return true
26
+ end
27
+ end
28
+
29
+ class Class
30
+ #--
31
+ # gmosx: is this really needed?
32
+ #++
33
+
34
+ def to_i
35
+ return self.hash
36
+ end
37
+ end
38
+
39
+ module Kernel
40
+
41
+ # Pretty prints an exception/error object
42
+ # usefull for helpfull debug messages
43
+ #
44
+ # Input:
45
+ # The Exception/StandardError object
46
+ #
47
+ # Output:
48
+ # the pretty printed string
49
+
50
+ def pp_exception(ex)
51
+ return %{#{ex.message}\n\tBACKTRACE:\n\t#{ex.backtrace.join("\n\t")}\n\tLOGGED FROM:\n\t#{caller[0]}}
52
+ end
53
+
54
+ end
5
55
 
6
56
  module Glue
7
57
 
8
- VERSION = '0.0.1'
9
- DOMAIN = 'gluenow.com'
58
+ # The version.
10
59
 
11
- class AuthError < StandardError; end
12
- class FormatHelper; include HTTParty; format :xml; end
60
+ Version = '0.13.0'
13
61
 
14
- class API < Glue::FormatHelper
15
-
16
- POST = '/api/post'
17
- USER = '/api/user'
18
-
19
- def initialize subdomain, user, pass
20
- raise AuthError, 'Username, Password or Account subdomain is blank.' \
21
- if subdomain.empty? || user.empty? || pass.empty?
22
- @auth = { :username => user, :password => pass }
23
- @site = "#{subdomain}.#{DOMAIN}"
24
- self.class.base_uri @site
25
- end
26
-
27
- def valid_site?
28
- Nokogiri::HTML(open("http://#{@site}")).at('body#login') ? true : false
29
- end
30
-
31
- def user_info
32
- self.class.post(USER, :query => {}, :basic_auth => @auth)
33
- end
34
-
35
- def post title, body, *opts
36
- self.class.post(
37
- POST,
38
- :query => {
39
- :title => title,
40
- :body => body,
41
- :draft => opts.include?( :draft ) ,
42
- :author => opts.include?( :author ) },
43
- :basic_auth => @auth
44
- )
45
- end
46
-
47
- end
48
-
49
- class RSS < Glue::FormatHelper
50
-
51
- NEWS = '/news/rss'
52
-
53
- def initialize subdomain
54
- raise AuthError, 'Account Subdomain is missing or blank' if subdomain.empty?
55
- self.class.base_uri "#{subdomain}.#{DOMAIN}"
56
- end
57
-
58
- def feed limit=999, page=1
59
- self.class.get("#{NEWS}?limit=#{limit}&page=#{page}")
60
- end
61
-
62
- end
63
-
64
- end
62
+ end
data/lib/glue/array.rb ADDED
@@ -0,0 +1,61 @@
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2002-2005 Navel, all rights reserved.
3
+ # $Id: array.rb 282 2005-03-10 12:24:53Z gmosx $
4
+
5
+ require 'sync'
6
+
7
+ module N
8
+
9
+ # A thread-safe array. We use a sync object instead of a
10
+ # mutex, because it is re-entrant. An exclusive lock is
11
+ # needed when writing, a shared lock IS NEEDED when reading.
12
+
13
+ class SafeArray < Array
14
+
15
+ attr :sync
16
+
17
+ # gmosx: delegator is not used.
18
+
19
+ def initialize(delegator = nil)
20
+ @sync = Sync.new()
21
+ end
22
+
23
+ def << (value)
24
+ return @sync.synchronize(Sync::SH) { super }
25
+ end
26
+
27
+ def delete_if(&block)
28
+ return @sync.synchronize(Sync::SH) { super }
29
+ end
30
+
31
+ def [](key)
32
+ return @sync.synchronize(Sync::SH) { super }
33
+ end
34
+
35
+ def []=(key, value)
36
+ return @sync.synchronize(Sync::EX) { super }
37
+ end
38
+
39
+ def delete(key)
40
+ return @sync.synchronize(Sync::EX) { super }
41
+ end
42
+
43
+ def clear
44
+ @sync.synchronize(Sync::EX) { super }
45
+ end
46
+
47
+ def size
48
+ return @sync.synchronize(Sync::SH) { super }
49
+ end
50
+
51
+ def shift
52
+ return @sync.synchronize(::Sync::EX) { super }
53
+ end
54
+
55
+ def unshift(el)
56
+ return @sync.synchronize(::Sync::EX) { super }
57
+ end
58
+
59
+ end
60
+
61
+ end