module ROM::Files::Plugins::Schema::Stat
A plugin for automatically adding stat properties of file to the schema definition
@example Generic `__stat__` field with String type
schema do use :stat end
@example Specify another set of properties
schema do use :stat, properties: %i[] end
@api public
Constants
- ALIASES
- NAME
- TYPES
Public Class Methods
apply(schema, name: NAME, stats: EMPTY_ARRAY, aliases: EMPTY_HASH)
click to toggle source
@api private
# 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
Private Class Methods
build_property(schema, name, stat: ALIASES[name] || name, type: TYPES[stat])
click to toggle source
# File lib/rom/files/plugins/schema/stat.rb, line 74 def build_property(schema, name, stat: ALIASES[name] || name, type: TYPES[stat]) raise ArgumentError, "Unknown property #{(stat || name).inspect}" unless type type.meta(name: name, source: schema.name, __stat__: (stat == NAME) || stat) end