Class: Knjappserver::Log
- Inherits:
-
Knj::Datarow
- Object
- Knj::Datarow
- Knjappserver::Log
- Defined in:
- lib/include/class_log.rb
Class Method Summary collapse
Instance Method Summary collapse
- #comment ⇒ Object
- #cookie ⇒ Object
- #first_line ⇒ Object
- #get ⇒ Object
- #ip ⇒ Object
- #meta ⇒ Object
- #objects_html(ob_use) ⇒ Object
- #post ⇒ Object
- #session ⇒ Object
- #tag ⇒ Object
- #text ⇒ Object
Class Method Details
.add(d) ⇒ Object
57 58 59 |
# File 'lib/include/class_log.rb', line 57 def self.add(d) d.data[:date_saved] = Time.now if !d.data.key?(:date_saved) end |
.list(d, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/include/class_log.rb', line 6 def self.list(d, &block) sql = "SELECT #{table}.* FROM #{table}" if d.args["object_lookup"] data_val = d.ob.get_by(:Log_data_value, {"value" => d.args["object_lookup"].class.name}) return [] if !data_val #if this data-value cannot be found, nothing has been logged for the object. So just return empty array here and skip the rest. sql << " LEFT JOIN Log_link ON Log_link.log_id = #{table}.id AND Log_link.object_class_value_id = '#{d.db.esc(data_val.id)}' AND Log_link.object_id = '#{d.db.esc(d.args["object_lookup"].id)}' " end q_args = nil return_sql = false ret = self.list_helper(d) sql << ret[:sql_joins] sql << " WHERE 1=1" d.args.each do |key, val| case key when "object_lookup" sql << " AND Log_link.id IS NOT NULL" when "return_sql" return_sql = true when "tag" data_val = d.ob.get_by(:Log_data_value, {"value" => val}) if !data_val sql << " AND false" else sql << " AND Log.tag_data_id = '#{d.db.esc(data_val.id)}'" end when :cloned_ubuf q_args = {:cloned_ubuf => true} else raise "Invalid key: #{key}." end end sql << ret[:sql_where] sql << ret[:sql_order] sql << ret[:sql_limit] return sql if return_sql return d.ob.list_bysql(:Log, sql, q_args, &block) end |
Instance Method Details
#comment ⇒ Object
65 66 67 68 69 70 |
# File 'lib/include/class_log.rb', line 65 def comment return "" if self[:comment_data_id].to_i == 0 log_data = ob.get(:Log_data_value, self[:comment_data_id]) return "" if !log_data return log_data[:value] end |
#cookie ⇒ Object
87 88 89 |
# File 'lib/include/class_log.rb', line 87 def ob.args[:knjappserver].log_data_hash(self[:cookie_keys_data_id], self[:cookie_values_data_id]) end |
#first_line ⇒ Object
107 108 109 |
# File 'lib/include/class_log.rb', line 107 def first_line lines = self.text.to_s.split("\n").first.to_s end |
#get ⇒ Object
79 80 81 |
# File 'lib/include/class_log.rb', line 79 def get ob.args[:knjappserver].log_data_hash(self[:get_keys_data_id], self[:get_values_data_id]) end |
#ip ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/include/class_log.rb', line 99 def ip = self. return [:HTTP_X_FORWARDED_FOR] if .has_key?(:HTTP_X_FORWARDED_FOR) return [:REMOTE_ADDR] if .has_key?(:REMOTE_ADDR) return "[no ip logged]" end |
#meta ⇒ Object
91 92 93 |
# File 'lib/include/class_log.rb', line 91 def ob.args[:knjappserver].log_data_hash(self[:meta_keys_data_id], self[:meta_values_data_id]) end |
#objects_html(ob_use) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/include/class_log.rb', line 111 def objects_html(ob_use) html = "" first = true self.links.each do |link| obj = link.object(ob_use) html << ", " if !first first = false if first if obj.respond_to?(:html) html << obj.html else html << "#{obj.class.name}{#{obj.id}}" end end return html end |
#post ⇒ Object
83 84 85 |
# File 'lib/include/class_log.rb', line 83 def post ob.args[:knjappserver].log_data_hash(self[:post_keys_data_id], self[:post_values_data_id]) end |
#session ⇒ Object
95 96 97 |
# File 'lib/include/class_log.rb', line 95 def session ob.args[:knjappserver].log_data_hash(self[:session_keys_data_id], self[:session_values_data_id]) end |
#tag ⇒ Object
72 73 74 75 76 77 |
# File 'lib/include/class_log.rb', line 72 def tag return "" if self[:tag_data_id].to_i == 0 log_data = ob.get(:Log_data_value, self[:tag_data_id]) return "" if !log_data return log_data[:value] end |
#text ⇒ Object
61 62 63 |
# File 'lib/include/class_log.rb', line 61 def text return ob.get(:Log_data_value, self[:text_value_id])[:value] end |