class ROM::Files::Schema
Specialized schema for files adapter
@api public
Public Instance Methods
call(relation)
click to toggle source
Abstract method for creating a new relation based on schema definition
This can be used by views to generate a new relation automatically. In example a schema can project a relation, join any additional relations if it include_patterns attributes from other relations etc.
Default implementation is a no-op and it simply returns back untouched relation
@param [Relation] relation
@return [Relation]
@api public
# File lib/rom/files/schema.rb, line 26 def call(relation) relation.new(relation.dataset.with(row_proc: row_proc), schema: self) end
contents_for(tuple)
click to toggle source
@param tuple [Hash] @return [String]
# File lib/rom/files/schema.rb, line 56 def contents_for(tuple) contents = attributes.each_with_object([]) do |attr, result| result << tuple[attr.name] if attr.meta[DATA] end.compact contents.join if contents.any? end
finalize_associations!(relations:)
click to toggle source
Internal hook used during setup process
@see Schema#finalize_associations!
@api private
Calls superclass method
# File lib/rom/files/schema.rb, line 68 def finalize_associations!(relations:) super do associations.map do |definition| Files::Associations.const_get(definition.type).new(definition, relations) end end end
identify(tuple)
click to toggle source
@param tuple [Hash] @return [Pathname]
# File lib/rom/files/schema.rb, line 46 def identify(tuple) path = (primary_key_names || [ID]).map do |name| tuple[name] end.compact return unless path.any? Pathname(path.shift).join(*path) end
load_attributes(pathname)
click to toggle source
@param pathname [Pathname] @return [Hash{Symbol => Object}]
# File lib/rom/files/schema.rb, line 37 def load_attributes(pathname) attributes.each_with_object({}) do |attribute, result| result[attribute.name] = attribute.(pathname) result end end
row_proc()
click to toggle source
@return [Method, Proc]
# File lib/rom/files/schema.rb, line 31 def row_proc method(:load_attributes) end