module ROM::Files::Plugins::Schema::Shebang

A plugin for automatically adding shebang of file to the schema definition

@example Generic `DATA` field with String type

schema do
  use :shebang
end

@example Specify another type

schema do
  use :shebang, type: Types::YAML
end

@example Specify another name

# using other types
schema do
  use :shebang, name: :shebang
end

@api public

Constants

NAME
TYPE

Public Class Methods

apply(schema, name: NAME, type: TYPE) click to toggle source

@api private

# File lib/rom/files/plugins/schema/shebang.rb, line 42
def self.apply(schema, name: NAME, type: TYPE)
  shebang = type.meta(name: name, source: schema.name, __proc__: method(:read_shebang))

  schema.attributes.concat(
    schema.class.attributes([shebang], schema.attr_class)
  )
end
read_shebang(path) click to toggle source

@param path [Pathname] @return [String, nil]

# File lib/rom/files/plugins/schema/shebang.rb, line 36
def self.read_shebang(path)
  shebang = path.readlines.first || ''
  shebang[2..-1].chomp if shebang.match?(/\A#!/)
end