lib/knj/datarow_custom.rb in knjrbfw-0.0.52 vs lib/knj/datarow_custom.rb in knjrbfw-0.0.53
- old
+ new
@@ -4,10 +4,16 @@
#Used to determine if this is a knj-datarow-object.
def is_knj?
return true
end
+ #Initializes variables on the class from objects.
+ def self.datarow_init(d)
+ @@ob = d.ob
+ @@db = d.db
+ end
+
def self.has_one(arr)
arr.each do |val|
methodname = nil
colname = nil
classname = nil
@@ -26,17 +32,17 @@
methodname = classname.to_s.downcase if !methodname
colname = "#{classname.to_s.downcase}_id".to_sym if !colname
define_method(methodname) do
- return @ob.get_try(self, colname, classname)
+ return @@ob.get_try(self, colname, classname)
end
methodname_html = "#{methodname.to_s}_html".to_sym
define_method(methodname_html) do |*args|
obj = self.send(methodname)
- return @ob.events.call(:no_html, classname) if !obj
+ return @@ob.events.call(:no_html, classname) if !obj
raise "Class '#{classname}' does not have a 'html'-method." if !obj.respond_to?(:html)
return obj.html(*args)
end
end
@@ -61,17 +67,14 @@
def self.table
return self.name.split("::").last
end
def table
- return self.class.name.split("::").last
+ return self.class.table
end
- def initialize(d)
- @ob = d.ob
- data = d.data
-
+ def initialize(data, args)
if data.is_a?(Hash)
@data = Knj::ArrayExt.hash_sym(data)
@id = self.id
else
@id = data
@@ -93,17 +96,11 @@
return ret
end
#Returns a key from the hash that this object is holding or raises an error if it doesnt exist.
def [](key)
- if !@data
- raise "No data spawned on object."
- end
-
- if !@data.key?(key)
- raise "No such key: '#{key}'. Available keys are: '#{@data.keys.sort.join(", ")}'."
- end
-
+ raise "No data spawned on object." if !@data
+ raise "No such key: '#{key}'. Available keys are: '#{@data.keys.sort.join(", ")}'." if !@data.key?(key)
return @data[key]
end
#Returns the ID of the object.
def id
\ No newline at end of file