libisi 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +677 -0
- data/Manifest +89 -0
- data/Rakefile +34 -0
- data/lib/inifile.rb +119 -0
- data/lib/libisi.rb +948 -0
- data/lib/libisi/attribute.rb +32 -0
- data/lib/libisi/attribute/activerecord.rb +34 -0
- data/lib/libisi/attribute/base.rb +33 -0
- data/lib/libisi/base.rb +109 -0
- data/lib/libisi/bridge.rb +21 -0
- data/lib/libisi/bridge/base.rb +23 -0
- data/lib/libisi/bridge/java.rb +71 -0
- data/lib/libisi/bridge/python.rb +37 -0
- data/lib/libisi/cache.rb +21 -0
- data/lib/libisi/cache/base.rb +67 -0
- data/lib/libisi/cache/file_cache.rb +24 -0
- data/lib/libisi/chart.rb +21 -0
- data/lib/libisi/chart/base.rb +320 -0
- data/lib/libisi/chart/jfreechart.rb +682 -0
- data/lib/libisi/chart/jfreechart_generator.rb +206 -0
- data/lib/libisi/color.rb +21 -0
- data/lib/libisi/color/base.rb +66 -0
- data/lib/libisi/color/colortools.rb +92 -0
- data/lib/libisi/color/java.rb +44 -0
- data/lib/libisi/concept.rb +33 -0
- data/lib/libisi/concept/activerecord.rb +39 -0
- data/lib/libisi/concept/base.rb +58 -0
- data/lib/libisi/doc.rb +35 -0
- data/lib/libisi/doc/base.rb +414 -0
- data/lib/libisi/doc/html.rb +85 -0
- data/lib/libisi/doc/text.rb +98 -0
- data/lib/libisi/doc/wiki.rb +55 -0
- data/lib/libisi/environment.rb +21 -0
- data/lib/libisi/environment/base.rb +36 -0
- data/lib/libisi/environment/http.rb +105 -0
- data/lib/libisi/environment/rails.rb +27 -0
- data/lib/libisi/environment/root.rb +23 -0
- data/lib/libisi/fake_logger/logger.rb +61 -0
- data/lib/libisi/function/base.rb +30 -0
- data/lib/libisi/hal.rb +558 -0
- data/lib/libisi/instance.rb +27 -0
- data/lib/libisi/instance/activerecord.rb +21 -0
- data/lib/libisi/instance/base.rb +42 -0
- data/lib/libisi/log.rb +237 -0
- data/lib/libisi/mail/base.rb +32 -0
- data/lib/libisi/mail/tmail.rb +120 -0
- data/lib/libisi/parameter/base.rb +41 -0
- data/lib/libisi/property.rb +27 -0
- data/lib/libisi/property/base.rb +28 -0
- data/lib/libisi/reciever/base.rb +31 -0
- data/lib/libisi/reciever/socket.rb +31 -0
- data/lib/libisi/relation.rb +23 -0
- data/lib/libisi/request.rb +22 -0
- data/lib/libisi/request/base.rb +29 -0
- data/lib/libisi/request/http.rb +129 -0
- data/lib/libisi/response/base.rb +27 -0
- data/lib/libisi/task/base.rb +27 -0
- data/lib/libisi/task/http.rb +90 -0
- data/lib/libisi/tee.rb +296 -0
- data/lib/libisi/ui/base.rb +116 -0
- data/lib/libisi/ui/console.rb +238 -0
- data/lib/libisi/ui/kde.rb +94 -0
- data/lib/libisi/ui/nobody.rb +29 -0
- data/lib/libisi/ui/rails.rb +150 -0
- data/lib/libisi/ui/x11.rb +55 -0
- data/lib/libisi/uri.rb +42 -0
- data/lib/libisi/uri/activerecord.rb +152 -0
- data/lib/libisi/uri/base.rb +115 -0
- data/lib/libisi/uri/file.rb +43 -0
- data/lib/libisi/uri/ldap.rb +72 -0
- data/lib/libisi/uri/mysql.rb +98 -0
- data/lib/libisi/value.rb +31 -0
- data/lib/libisi/value/attribute_value.rb +19 -0
- data/lib/libisi/value/base.rb +55 -0
- data/lib/libisi/value/property_value.rb +19 -0
- data/lib/libisi/value/relation_value.rb +19 -0
- data/lib/ordered_hash.rb +228 -0
- data/libisi.gemspec +31 -0
- data/test/bridge_test.rb +77 -0
- data/test/cache_test.rb +65 -0
- data/test/chart_test.rb +179 -0
- data/test/color_test.rb +64 -0
- data/test/concept_test.rb +56 -0
- data/test/doc_test.rb +172 -0
- data/test/fixtures/test.db +0 -0
- data/test/ordered_hash_test.rb +39 -0
- data/test/profile_test.rb +36 -0
- data/test/request_test.rb +121 -0
- data/test/test +0 -0
- data/test/ui_test.rb +62 -0
- metadata +244 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
class BaseUri
|
|
19
|
+
|
|
20
|
+
attr_accessor :uri, :options
|
|
21
|
+
|
|
22
|
+
def initialize(uri, options = {})
|
|
23
|
+
@uri = uri
|
|
24
|
+
@options = options
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def credential_hash
|
|
28
|
+
uis = (uri.userinfo or "").split(":")
|
|
29
|
+
ret = {}
|
|
30
|
+
# URI unescape to allow special characters,
|
|
31
|
+
# probably not rfc conform
|
|
32
|
+
ret[:user] = URI.unescape(uis[0]) if uis[0]
|
|
33
|
+
ret[:password] = URI.unescape(uis[1]) if uis[1]
|
|
34
|
+
ret
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def base_uri
|
|
38
|
+
u = uri.dup
|
|
39
|
+
u.path = ""
|
|
40
|
+
u
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def user
|
|
44
|
+
options[:user] or credential_hash[:user]
|
|
45
|
+
end
|
|
46
|
+
def password
|
|
47
|
+
options[:password] or credential_hash[:password] or
|
|
48
|
+
(options[:use_password] and $ui.password("Please enter password for #{base_uri.to_s}"))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def execute_command(command)
|
|
52
|
+
return command if uri.host == "localhost"
|
|
53
|
+
l = uri.host
|
|
54
|
+
# l = "#{uri.userinfo}@#{l}" if uri.userinfo
|
|
55
|
+
execute_on_remote_command(l, command)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def find(*args)
|
|
59
|
+
options = {}
|
|
60
|
+
options = args.pop if args[-1].class == Hash
|
|
61
|
+
|
|
62
|
+
raise "No more than one argument allowed at the moment" if
|
|
63
|
+
args.length > 1
|
|
64
|
+
|
|
65
|
+
m_items = (self.items or [])
|
|
66
|
+
if conditions = options[:conditions]
|
|
67
|
+
conditions.each {|field, value|
|
|
68
|
+
raise "Only unless Symbol => (Regex|String) pairs allowed for conditions:" +
|
|
69
|
+
"#{field.inspect}(#{field.class.name}) => #{value.inspect}(#{value.class.name})" if
|
|
70
|
+
field.class != Symbol or ![String,Regexp].include?(value.class)
|
|
71
|
+
|
|
72
|
+
$log.debug("Filtering items for #{field} => #{value}")
|
|
73
|
+
|
|
74
|
+
case value
|
|
75
|
+
when String
|
|
76
|
+
compare_proc = Proc.new {|v| v == value }
|
|
77
|
+
when Regexp
|
|
78
|
+
compare_proc = Proc.new {|v| v =~ value }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
m_items = m_items.select {|i|
|
|
82
|
+
item_value = i.send(field )
|
|
83
|
+
case item_value
|
|
84
|
+
when String
|
|
85
|
+
compare_proc.call(item_value)
|
|
86
|
+
when Array
|
|
87
|
+
item_value.select{|v| compare_proc.call(v)}.length > 0
|
|
88
|
+
when NilClass
|
|
89
|
+
false
|
|
90
|
+
else
|
|
91
|
+
raise "Item field value #{item_value.inspect} of #{i.inspect} has unexpected type #{item_value.class.name}"
|
|
92
|
+
end
|
|
93
|
+
}
|
|
94
|
+
$log.debug("There are still #{m_items.length} items after filter #{field} => #{value}")
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
case args.first
|
|
99
|
+
when :first then m_items[0]
|
|
100
|
+
when :last then m_items[-1]
|
|
101
|
+
when :all then m_items
|
|
102
|
+
else
|
|
103
|
+
key_proc = primary_key
|
|
104
|
+
key_proc = Proc.new {|i| i.send(primary_key)} if primary_key.class == String
|
|
105
|
+
m_items.each {|i|
|
|
106
|
+
return i if key_proc.call(i).to_s == args.first.to_s
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
raise self.entry_not_found_exception if self.respond_to?(:entry_not_found_exception)
|
|
110
|
+
raise "Item #{args.first} not found"
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
require "libisi/uri/base"
|
|
19
|
+
class FileData < BaseUri
|
|
20
|
+
|
|
21
|
+
def initialize(uri, options = {})
|
|
22
|
+
super
|
|
23
|
+
raise "Only local files allowed. Host is #{uri.host}" unless
|
|
24
|
+
["127.0.0.1","localhost"].include?(uri.host)
|
|
25
|
+
@file = Pathname.new(uri.path[1..-1])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def file; @file; end
|
|
29
|
+
def pathname; @file; end
|
|
30
|
+
|
|
31
|
+
def primary_key; Proc.new {|pathname| pathname.basename.to_s}; end
|
|
32
|
+
|
|
33
|
+
def column_names; ["size","dirname","basename"]; end
|
|
34
|
+
|
|
35
|
+
def items
|
|
36
|
+
if @file.directory?
|
|
37
|
+
@file.entries
|
|
38
|
+
else
|
|
39
|
+
@file.readlines
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
require "libisi/uri/base"
|
|
19
|
+
class LdapData < BaseUri
|
|
20
|
+
@@num = 0
|
|
21
|
+
|
|
22
|
+
require "active_ldap"
|
|
23
|
+
|
|
24
|
+
def initialize(uri, options = {})
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def primary_key; ldap_class.dn_attribute ;end
|
|
29
|
+
|
|
30
|
+
def column_names;
|
|
31
|
+
return @column_names if @column_names
|
|
32
|
+
$log.debug("Finding column names")
|
|
33
|
+
@column_names = items.map {|i| i.attribute_names}.flatten.uniq.compact.sort
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def items; ldap_class.find(:all); end
|
|
37
|
+
def entry_not_found_exception; ActiveLdap::EntryNotFound; end
|
|
38
|
+
def create(attributes,&block); ldap_class.create(attributes,&block) ;end
|
|
39
|
+
def new(attributes, &block); ldap_class.new(attributes, &block); end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
def ldap_class
|
|
43
|
+
return @myclass if @myclass
|
|
44
|
+
|
|
45
|
+
LdapData.module_eval("class LdapClass#{@@num} < ActiveLdap::Base; end")
|
|
46
|
+
@myclass = eval("LdapClass#{@@num}")
|
|
47
|
+
@@num += 1
|
|
48
|
+
|
|
49
|
+
path_items = uri.path.split("/")[1..-1]
|
|
50
|
+
base = path_items[0]
|
|
51
|
+
$log.debug("Base dn: #{base}")
|
|
52
|
+
$log.debug("Bind dn: #{user}")
|
|
53
|
+
|
|
54
|
+
@myclass.setup_connection(
|
|
55
|
+
:host => uri.host,
|
|
56
|
+
:port => (uri.port or 389),
|
|
57
|
+
:base => base,
|
|
58
|
+
:logger => $log,
|
|
59
|
+
:bind_dn => user,
|
|
60
|
+
:password_block => Proc.new { password },
|
|
61
|
+
:allow_anonymous => false,
|
|
62
|
+
:try_sasl => false,
|
|
63
|
+
:method => (options[:method] or "tls") #:tls, :ssl, :plain
|
|
64
|
+
)
|
|
65
|
+
klass = path_items[1..-2].reverse.join(",")
|
|
66
|
+
$log.debug("prefix: #{klass}")
|
|
67
|
+
dn = path_items[-1]
|
|
68
|
+
$log.debug("dn_attribute: #{dn}")
|
|
69
|
+
@myclass.ldap_mapping :prefix => klass,:dn_attribute => dn
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
require "libisi/uri/base"
|
|
19
|
+
class MysqlData < BaseUri
|
|
20
|
+
|
|
21
|
+
def initialize(uri, options = {})
|
|
22
|
+
super
|
|
23
|
+
self.database
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def database
|
|
27
|
+
db = uri.path
|
|
28
|
+
db = db[1..-1] if db =~ /^\//
|
|
29
|
+
raise "Unexpected database name #{db}" if db =~ /\//
|
|
30
|
+
db
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def mysql_command(command = "mysql")
|
|
34
|
+
cmd = command
|
|
35
|
+
cmd += " -u #{user}" if user
|
|
36
|
+
cmd += " -p#{password}" if password
|
|
37
|
+
cmd
|
|
38
|
+
end
|
|
39
|
+
def execute_mysql(sql)
|
|
40
|
+
execute_command("echo '#{sql}' | " + mysql_command)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def source_command
|
|
44
|
+
cmd = mysql_command("mysqldump")
|
|
45
|
+
if uri.path
|
|
46
|
+
cmd += " #{database}"
|
|
47
|
+
else
|
|
48
|
+
cmd += " --all-databases"
|
|
49
|
+
end
|
|
50
|
+
cmd
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def target_command
|
|
54
|
+
cmd = mysql_command
|
|
55
|
+
cmd += " #{database}" if uri.path
|
|
56
|
+
cmd
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def copy_command(target = nil)
|
|
60
|
+
raise "Convert mysql to #{target.class} not implemented." unless target.class == self.class or target.class == NilClass
|
|
61
|
+
raise "You must specify a source database if you give a target database." if database.nil? and database
|
|
62
|
+
|
|
63
|
+
ret = execute_command(source_command)
|
|
64
|
+
if target
|
|
65
|
+
ret += "|" + target.execute_command(target.target_command)
|
|
66
|
+
end
|
|
67
|
+
ret
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def readable_command
|
|
71
|
+
if database
|
|
72
|
+
execute_command("echo 'show tables' | " + mysql_command + " #{database} 2>&1 > /dev/null")
|
|
73
|
+
else
|
|
74
|
+
execute_command("echo 'show databases' | " + mysql_command + " 2>&1 > /dev/null")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def make_readable_command
|
|
79
|
+
if database
|
|
80
|
+
execute_mysql("GRANT SELECT, LOCK TABLES ON #{database}.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
|
|
81
|
+
else
|
|
82
|
+
execute_mysql("GRANT SELECT, LOCK TABLES ON *.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def create_command
|
|
87
|
+
execute_mysql("CREATE DATABASE #{database}")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def make_writable_command
|
|
91
|
+
if database
|
|
92
|
+
execute_mysql("GRANT ALL ON #{database}.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
|
|
93
|
+
else
|
|
94
|
+
execute_mysql("GRANT ALL ON *.* TO #{user}@localhost IDENTIFIED BY \"#{password}\"")
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
data/lib/libisi/value.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
require "libisi/base.rb"
|
|
19
|
+
require "libisi/value/base.rb"
|
|
20
|
+
class Value < Base
|
|
21
|
+
|
|
22
|
+
def self.create(source, instance, options = {})
|
|
23
|
+
case source.class.name
|
|
24
|
+
when /Attribute/,/Property/
|
|
25
|
+
BaseValue.new(source, instance, options)
|
|
26
|
+
else
|
|
27
|
+
raise "Unexpected source for new value #{source.class.name}"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
class AttributeValue < BaseValue
|
|
19
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
class BaseValue
|
|
19
|
+
|
|
20
|
+
attr_reader :source, :instance
|
|
21
|
+
|
|
22
|
+
def initialize(source, instance, options = {})
|
|
23
|
+
@source = source
|
|
24
|
+
@instance = instance
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def unit; source.respond_to?(:unit) and source.unit; end
|
|
28
|
+
def type; source.respond_to?(:type) and source.type; end
|
|
29
|
+
def name; source.name; end
|
|
30
|
+
|
|
31
|
+
def data_object; instance.send(name); end
|
|
32
|
+
def to_s; data_object.to_s; end
|
|
33
|
+
def inspect; "#{to_s} <#{type or "?"}/#{unit or "?"}>"; end
|
|
34
|
+
|
|
35
|
+
def to_doc(options)
|
|
36
|
+
raise "No doc initialized" unless $doc
|
|
37
|
+
|
|
38
|
+
case type
|
|
39
|
+
when :integer
|
|
40
|
+
i = data_object
|
|
41
|
+
if i < 0
|
|
42
|
+
$doc.print(:color => "red") {
|
|
43
|
+
i.to_s
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
$doc.print {
|
|
47
|
+
i.to_s
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
}
|
|
51
|
+
when :text
|
|
52
|
+
$doc.p { data_object.to_s }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
class PropertyValue < BaseValue
|
|
19
|
+
end
|