udjrb 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/lib/udjrb.rb +60 -0
- data/lib/udjrb/asjava.jar +0 -0
- data/lib/udjrb/version.rb +3 -0
- data/udjrb.gemspec +19 -0
- metadata +64 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
UDJrb is a set of classes and extensions to make it easier to work with the UniData Java API. UDJrb includes a copy of `asjava.jar`, and loads it automatically when you require the library. So, all you need to get start is to install UDJrb via `gem install udjrb` and require it with `require 'udjrb'`.
|
2
|
+
|
3
|
+
UDJrb::Session
|
4
|
+
==============
|
5
|
+
|
6
|
+
To connect to a UniData database, use the `UDJrb::Session` object.
|
7
|
+
|
8
|
+
session = UDJrb::Session.new "username", "password", "host", "account"
|
9
|
+
|
10
|
+
This will automatically connect you to the database. Once you're connected, there are a few methods available to you:
|
11
|
+
|
12
|
+
* `session.unijava` - returns the underlying `asjava.uniobjects.UniJava` object.
|
13
|
+
* `session.session` - returns the underlying `UniSession` object.
|
14
|
+
* `session.disconnect` - disconnect cleanly from the database (uses `UniJava#closeSession()`).
|
15
|
+
|
16
|
+
Any other method you call will be passed through to the underlying `UniSession` object, which means you can open files, etc. just by calling the method you would normally call on a `UniSession` instance:
|
17
|
+
|
18
|
+
person = session.open "PERSON"
|
19
|
+
person.set_record_id "0123456"
|
20
|
+
puts "First Name: #{person.read_named_field 'FIRST.NAME'}"
|
21
|
+
puts "Last Name: #{person.read_named_field 'LAST.NAME'}"
|
22
|
+
|
23
|
+
UniFile Extensions
|
24
|
+
==================
|
25
|
+
|
26
|
+
The following extensions have been added to `UniFile`:
|
27
|
+
|
28
|
+
* `file.data(field)` - convienence method for `file.read_named_field(field)`.
|
29
|
+
|
30
|
+
UniDynArray Extensions
|
31
|
+
======================
|
32
|
+
|
33
|
+
The following extensions have been added to `UniDynArray`:
|
34
|
+
|
35
|
+
* `each` - returns each value from the first field in the array (`to_s` is called on each element).
|
36
|
+
* `include Enumerable` - gives access to the [Enumerable](http://www.ruby-doc.org/core/classes/Enumerable.html) methods by way of `each`.
|
data/Rakefile
ADDED
data/lib/udjrb.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
include Java
|
2
|
+
require File.expand_path "./udjrb/asjava.jar", File.dirname(__FILE__)
|
3
|
+
|
4
|
+
module UDJrb
|
5
|
+
# Lazy-load the UniJava object
|
6
|
+
def self.unijava
|
7
|
+
@unijava = Java::asjava.uniobjects.UniJava.new if @unijava.nil?
|
8
|
+
@unijava
|
9
|
+
end
|
10
|
+
|
11
|
+
class Session
|
12
|
+
def initialize(user, pass, host, account)
|
13
|
+
@session = unijava.open_session
|
14
|
+
|
15
|
+
@session.set_user_name user
|
16
|
+
@session.set_password pass
|
17
|
+
@session.set_host_name host
|
18
|
+
@session.set_account_path account
|
19
|
+
@session.set_data_source_type "UNIDATA"
|
20
|
+
|
21
|
+
@session.connect
|
22
|
+
end
|
23
|
+
|
24
|
+
def unijava
|
25
|
+
UDJrb.unijava
|
26
|
+
end
|
27
|
+
|
28
|
+
def session
|
29
|
+
@session
|
30
|
+
end
|
31
|
+
|
32
|
+
def disconnect
|
33
|
+
unijava.close_session @session
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(method, args)
|
37
|
+
@session.send method, args
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Java::AsjavaUniobjects::UniFile
|
43
|
+
# Extension to make it easier to read data from a file.
|
44
|
+
def data(field)
|
45
|
+
self.read_named_field(field)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Java::AsjavaUniclientlibs::UniDynArray
|
50
|
+
# Extension to treat UniDynArray as Enumerable.
|
51
|
+
# Note that using each or any of the resulting methods
|
52
|
+
# from Enumerable treats each element in the UniDynArray
|
53
|
+
# as a string (to_s is called on each element extracted).
|
54
|
+
include Enumerable
|
55
|
+
def each
|
56
|
+
0.upto count(1) do |n|
|
57
|
+
yield self.extract(1, n+1).to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
Binary file
|
data/udjrb.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "udjrb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "udjrb"
|
7
|
+
s.version = UDJrb::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Brandon Tilley"]
|
10
|
+
s.email = ["brandon@brandontilley.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Classes and extensions to make working with the UniData Java API easier.}
|
13
|
+
s.description = %q{Classes and extensions to make working with the UniData Java API easier.}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: udjrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brandon Tilley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-13 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Classes and extensions to make working with the UniData Java API easier.
|
18
|
+
email:
|
19
|
+
- brandon@brandontilley.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- lib/udjrb.rb
|
32
|
+
- lib/udjrb/asjava.jar
|
33
|
+
- lib/udjrb/version.rb
|
34
|
+
- udjrb.gemspec
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: ""
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.5.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Classes and extensions to make working with the UniData Java API easier.
|
63
|
+
test_files: []
|
64
|
+
|