Module: ROM::Files::Plugins::Schema::Shebang

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

Overview

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

Examples:

Generic DATA field with String type

schema do
  use :shebang
end

Specify another type

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

Specify another name

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

Defined Under Namespace

Modules: DSL

Constant Summary collapse

TYPE =
Types::String
NAME =
:run_with

Class Method Summary collapse

Class Method Details

.apply(schema, name: NAME, type: TYPE) ⇒ 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.



42
43
44
45
46
47
48
# 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) ⇒ String?

Parameters:

Returns:

  • (String, nil)


36
37
38
39
# 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