module HaveAPI::Fs::Components
class Executable < File
def executable?
true
end
def writable?
true
end
def read
abs_path = ::File.join(context.mountpoint, path)
"#!\#{RbConfig.ruby}\n#\n# This action can be executed either by running this file or by writing \"1\" to\n# it, e.g.:\n# \n# .\#{abs_path}\n#\n# or\n#\n# echo 1 > \#{abs_path}\n#\nrequire 'yaml'\n\nf = ::File.open(\n '\#{::File.join(context.mountpoint, '.remote_control')}',\n 'w+'\n)\nf.write(YAML.dump({\n action: :execute,\n path: '/\#{path}',\n}))\nf.write(\#{RemoteControlFile::MSG_DELIMITER.dump})\nf.flush\nf.seek(0)\n\nret = YAML.load(f.read)\nf.close\n\nunless ret[:status]\n warn \"Action failed: \\\#{ret[:message]}\"\n if ret[:errors]\n ret[:errors].each do |k, v|\n warn \" \\\#{k}: \\\#{v.join('; ')}\"\n end\n end\nend\n\nexit(ret[:status])\n"
end
def write(str)
exec if str.strip == '1'
end
def exec
raise NotImplementedError
end
end
end