Skip to content

Instantly share code, notes, and snippets.

@matthewd
Created Jun 25, 2015
Embed
What would you like to do?
diff --git a/vmdb/lib/acts_as_ar_model.rb b/vmdb/lib/acts_as_ar_model.rb
index e23a20f..d6838a8 100644
--- a/vmdb/lib/acts_as_ar_model.rb
+++ b/vmdb/lib/acts_as_ar_model.rb
@@ -1,16 +1,3 @@
-class ActsAsArModelColumn < ActiveRecord::ConnectionAdapters::Column
- attr_reader :options
-
- def initialize(name, options)
- type = options.kind_of?(Symbol) ? options : options[:type]
- raise ArgumentError, "type must be specified" if type.nil?
-
- @options = options.kind_of?(Hash) ? options : {}
-
- super(name.to_s, @options[:default], type.to_s)
- end
-end
-
class ActsAsArModel
def self.connection
ActiveRecord::Base.connection
@@ -43,26 +30,27 @@ class ActsAsArModel
#
def self.columns_hash
- @columns_hash ||= {}
+ {}
end
def self.columns
- @columns ||= self.columns_hash.values
+ []
end
def self.column_names
- @column_names ||= self.columns_hash.keys
+ []
end
def self.column_names_symbols
- @column_names_symbols ||= self.column_names.collect(&:to_sym)
+ []
end
def self.set_columns_hash(hash)
hash[:id] ||= :integer
hash.each do |col, options|
- self.columns_hash[col.to_s] = ActsAsArModelColumn.new(col.to_s, options)
+ options = {:type => options} if options.kind_of?(Symbol)
+ add_virtual_column col.to_s, options
define_method(col) do
read_attribute(col)
@@ -79,7 +67,7 @@ class ActsAsArModel
#
def self.reflections
- @reflections ||= {}
+ {}
end
#
diff --git a/vmdb/lib/extensions/ar_virtual.rb b/vmdb/lib/extensions/ar_virtual.rb
index e762f85..59b8ae2 100644
--- a/vmdb/lib/extensions/ar_virtual.rb
+++ b/vmdb/lib/extensions/ar_virtual.rb
@@ -23,6 +23,7 @@ class VirtualColumn < ActiveRecord::ConnectionAdapters::Column
:integer => ActiveRecord::Type::Integer.new, # TODO: does a virtual_column :integer care if it's a Integer or BigInteger
:numeric_set => Type::NumericSet.new,
:string => ActiveRecord::Type::String.new,
+ :text => ActiveRecord::Type::String.new,
:string_set => Type::StringSet.new,
:symbol => Type::Symbol.new, # TODO: is this correct?
:time => ActiveRecord::Type::Time.new,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment