Sha256: c070e7c9d69ddbdedc0d2a860254d19582efa15bcd49a0d6f6016052a6adb688
Contents?: true
Size: 1.29 KB
Versions: 5
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true class PGTrunk::Operation # @private # Register attributes definition for later usage by generators module Generators extend ActiveSupport::Concern class_methods do # Gets or sets object name for the generator def generates_object(name = nil) @generates_object = name if name @generates_object ||= nil end # The definitions of the attributes # @return [Hash{Symbol => Hash{type:, default:, desc:}}] def attributes @attributes ||= {} end def attribute(name, type, default: nil, desc: nil, **opts) name = name.to_sym attributes[name] = { type: gen_type(type), default: default, desc: desc, } super(name, type.to_sym, default: default, **opts) end private def inherited(klass) klass.instance_variable_set(:@attributes, attributes.dup) super end # Convert the type to the acceptable by Rails::Generator def gen_type(type) case type.to_s when "bool", "boolean" then :boolean when "integer", "float" then :numeric when /^pg_trunk_array/ then :array when /^pg_trunk_hash/ then :hash else :string end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems