module PGTrunk::Operation::Generators

@private Register attributes definition for later usage by generators

Public Instance Methods

attribute(name, type, default: nil, desc: nil, **opts) click to toggle source
Calls superclass method
# File lib/pg_trunk/core/operation/generators.rb, line 22
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
attributes() click to toggle source

The definitions of the attributes @return [Hash{Symbol => Hash{type:, default:, desc:}}]

# File lib/pg_trunk/core/operation/generators.rb, line 18
def attributes
  @attributes ||= {}
end
gen_type(type) click to toggle source

Convert the type to the acceptable by Rails::Generator

# File lib/pg_trunk/core/operation/generators.rb, line 40
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
generates_object(name = nil) click to toggle source

Gets or sets object name for the generator

# File lib/pg_trunk/core/operation/generators.rb, line 11
def generates_object(name = nil)
  @generates_object = name if name
  @generates_object ||= nil
end
inherited(klass) click to toggle source
Calls superclass method
# File lib/pg_trunk/core/operation/generators.rb, line 34
def inherited(klass)
  klass.instance_variable_set(:@attributes, attributes.dup)
  super
end