Skip to content

Instantly share code, notes, and snippets.

@universal
Last active June 29, 2017 08:41
Show Gist options
  • Save universal/1111882ce9a2e1c05a2761f322525bf4 to your computer and use it in GitHub Desktop.
Save universal/1111882ce9a2e1c05a2761f322525bf4 to your computer and use it in GitHub Desktop.
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module ArkMonitor
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.generators do |g|
g.test_framework :rspec,
fixtures: true,
view_specs: false,
helper_specs: false,
routing_specs: false,
controller_specs: false,
request_specs: false
g.fixture_replacement :factory_girl, dir: "spec/factories"
g.assets false
g.helper false
end
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :en
config.time_zone = 'Berlin'
config.x.steam = Rails.application.config_for(:steam)
end
end
# app/models/factorio/configuration.rb
class Factorio::Configuration < ApplicationRecord
belongs_to :server
validates :file, presence: true
def read
self.content = File.read current_path
self.update_attributes read_at: Time.now
self
end
def write
File.open current_path, "w" do |config|
config.puts self.content
end
self.update_attributes wrote_at: Time.now
self
end
def modified_at
File.mtime(current_path) if File.exists? current_path
end
def copy from:
FileUtils.cp version_path(version: from), current_path if File.exists? version_path(version: from)
end
private
def current_path
[self.server.current_path, "data", self.file].join("/")
end
def version_path version:
[self.server.version_path(version: version), "data", self.file].join("/")
end
end
# app/models/factorio.rb
module Factorio
def self.table_name_prefix
'factorio_'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment