class Pliny::Commands::Generator::Schema

Public Class Methods

new(*) click to toggle source
Calls superclass method Pliny::Commands::Generator::Base::new
# File lib/pliny/commands/generator/schema.rb, line 7
def initialize(*)
  super
  @warned_legacy = false
end

Public Instance Methods

create() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 12
def create
  warn_legacy if legacy?

  schema = schema_yaml_path(field_name)
  write_file(schema) do
    Prmd.init(name.singularize, yaml: true)
  end
  display "created schema file #{schema}"
end
legacy?() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 31
def legacy?
  File.exist?("./docs/schema.json") || File.directory?("./docs/schema/schemata")
end
meta_path() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 49
def meta_path
  if legacy?
    "./docs/schema/meta.json"
  else
    "./schema/meta.json"
  end
end
rebuild() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 22
def rebuild
  warn_legacy if legacy?

  write_file(schema_json_path) do
    Prmd.combine(schemata_path, meta: meta_path)
  end
  display "rebuilt #{schema_json_path}"
end
schema_base() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 65
def schema_base
  Pathname.new("./schema")
end
schema_json_path() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 41
def schema_json_path
  if legacy?
    "./docs/schema.json"
  else
    "./schema/schema.json"
  end
end
schema_yaml_path(field_name) click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 69
def schema_yaml_path(field_name)
  File.join(schemata_path, "#{field_name}.yaml")
end
schemata_path() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 57
def schemata_path
  if legacy?
    "./docs/schema/schemata"
  else
    "./schema/schemata"
  end
end
warn_legacy() click to toggle source
# File lib/pliny/commands/generator/schema.rb, line 35
def warn_legacy
  return if @warned_legacy
  display "WARNING: Using legacy schema layout under docs/. To use new layout under schema/, run `mkdir -p schema && git mv docs/schema.json docs/schema/meta.* docs/schema/schemata schema` then check for remaining schema-related files under docs/."
  @warned_legacy = true
end