Sha256: 5156e63aa850e829fe6bc63df5a6e52da742a59add9f8e1066249d17de7a87e5
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
class ActiveRecordSchemaScrapper class Attributes def initialize(model:) @model = model @errors = [] end include Enumerable def each call.each { |attr| yield(attr) } end def to_a map { |v| v } end def self.register_type(name:, klass:) registered_types << [name, klass] end def self.registered_types @registered_types ||= [] end def self.register_default(name:, klass:) registered_defaults << [name, klass] end def self.registered_defaults @registered_defaults ||= [] end attr_reader :errors private attr_reader :model def call @attributes ||= model.columns_hash.map do |k, v| ActiveRecordSchemaScrapper::Attribute.new( name: k, type: v.type, precision: v.cast_type.precision, limit: v.cast_type.limit, scale: v.cast_type.scale, default: v.default, null: v.null, ) end rescue NoMethodError => e @errors << OpenStruct.new(class_name: model.name, message: "#{model.name} is not a valid ActiveRecord model.", original_error: e) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_record_schema_scrapper-0.1.2 | lib/active_record_schema_scrapper/attributes.rb |