Module: ROM::Files::Plugins::Schema::Stat

Defined in:
lib/rom/files/plugins/schema/stat.rb

Overview

A plugin for automatically adding stat properties of file to the schema definition

Examples:

Generic __stat__ field with String type

schema do
  use :stat
end

Specify another set of properties

schema do
  use :stat, properties: %i[]
end

Defined Under Namespace

Modules: DSL

Constant Summary collapse

NAME =
:stat
TYPES =
{
  atime: Types::Time,
  basename: Types::String,
  birthtime: Types::Time,
  blksize: Types::Int.optional,
  blocks: Types::Int.optional,
  ctime: Types::Time,
  dev: Types::Int,
  dev_major: Types::Int,
  dev_minor: Types::Int,
  ftype: Types::FileType,
  gid: Types::Int,
  ino: Types::Int,
  mode: Types::Int,
  mtime: Types::Time,
  nlink: Types::Int,
  rdev: Types::Int,
  rdev_major: Types::Int,
  rdev_minor: Types::Int,
  size: Types::Int,
  uid: Types::Int
}.freeze
ALIASES =
{
  accessed_at: :atime,
  changed_at: :ctime,
  updated_at: :mtime,
  created_at: :birthtime,
  type: :ftype
}.freeze

Class Method Summary collapse

Class Method Details

.apply(schema, name: NAME, stats: EMPTY_ARRAY, aliases: EMPTY_HASH) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rom/files/plugins/schema/stat.rb', line 59

def apply(schema, name: NAME, stats: EMPTY_ARRAY, aliases: EMPTY_HASH)
  attributes = []
  attributes = [build_property(schema, name, type: Types::FileStat)] if name
  attributes += stats.map { |stat| build_property(schema, stat) }
  attributes += aliases.map do |as, stat|
    build_property(schema, as, stat: stat)
  end

  schema.attributes.concat(
    schema.class.attributes(attributes, schema.attr_class)
  )
end