Sha256: 47402808a31188ba1013c46618412e009a3c28bc5a650f9efe1e847766a65253
Contents?: true
Size: 815 Bytes
Versions: 1
Compression:
Stored size: 815 Bytes
Contents
module LazyModel class LazyModel attr_accessor :model, :attribute, :enumerables, :custom_finders, :column def initialize(model, attribute, enumerables = nil, custom_finders = {}) self.model = model self.attribute = attribute self.enumerables = Array(enumerables) self.custom_finders = custom_finders end def define_methods #make sure the column exists unless self.column = model.columns_hash[attribute.to_s] raise "\'#{attribute}\' is not an attribute for \'#{model.to_s}\' model" end #pass to lazy class id supported begin klass = "LazyModel::Lazy#{column.type.to_s.camelize}".constantize klass.new(self).define_methods rescue NameError raise " attribute type \'#{column.type}\'' on \'#{attribute}\' is not supported " end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lazy_model-0.0.1 | lib/lazy_model/lazy_model.rb |