lib/katapult/attribute.rb in katapult-0.1.2 vs lib/katapult/attribute.rb in katapult-0.2.0

- old
+ new

@@ -6,20 +6,21 @@ require 'zlib' module Katapult class Attribute < Element - options :type, :default, :assignable_values, :allow_blank + options :type, :default, :assignable_values, :allow_blank, :skip_db UnknownTypeError = Class.new(StandardError) MissingOptionError = Class.new(StandardError) - TYPES = %i(string email url integer money text markdown flag datetime) + TYPES = %i(string email password url integer money text flag datetime json plain_json) def initialize(*args) super self.type ||= :email if name.to_s =~ /email/ + self.type ||= :password if name.to_s =~ /password/ self.type ||= :string validate end @@ -29,19 +30,16 @@ default and not [flag?, assignable_values].any? end def for_migration db_type = case type - when :email, :url - 'string' - when :flag - 'boolean' - when :money - 'decimal{10,2}' # {precision,scale} = total digits, decimal places - else - type - end + when :email, :url, :password then 'string' + when :flag then 'boolean' + when :money then 'decimal{10,2}' # {precision,scale} = total digits, decimal places + when :json then 'jsonb' # Indexable JSON + when :plain_json then 'json' # Only use this if you need to + else type end "#{name}:#{db_type}" end def test_value @@ -49,9 +47,10 @@ assignable_values.first else case type when :string then "#{name}-string" + when :password then "#{name}-password" when :email then "#{name}@example.com" when :url then "#{name}.example.com" when :text then "#{name}-text" # Deterministically generate a value from the attribute's name