class Kamishibai::Config

Attributes

bind[RW]
bookmarks_path[RW]
cache_path[RW]
config_path[RW]
db_path[RW]
default_image_quality[RW]
image_resize[RW]
new_book_days[RW]
password[RW]
port[RW]
srcs[RW]
username[RW]

Public Class Methods

new( path = '~/etc/kamishibai.conf' ) click to toggle source
# File lib/kamishibai/config.rb, line 15
def initialize( path = '~/etc/kamishibai.conf' )
        @config_path = File.expand_path( path )

        if File.exists?( @config_path )
                load
        else
                # settings template
                @srcs = []
                @image_resize = true
                @default_image_quality = 60
                @username = 'admin'
                @password = 'admin'
                @bind     = '0.0.0.0'
                @port     = 9999

                @db_path        = '~/var/kamishibai/db.json'
                @bookmarks_path = '~/var/kamishibai/bookmarks.json'
                @cache_path     = '~/var/kamishibai/cache/'

                @new_book_days = 7

                save_config
        end
end

Public Instance Methods

save() click to toggle source
# File lib/kamishibai/config.rb, line 40
def save
        unless FileTest.exists?( File.dirname( @config_path ) )
                FileUtils.mkdir_p( File.dirname( @config_path ) )
        end

        t = {}
        t[:srcs]         = @srcs.collect { |src| File.expand_path(src) }
        t[:image_resize] = @image_resize
        t[:default_image_quality] = @default_image_quality
        t[:username] = @username
        t[:password] = @password
        t[:bind]     = @bind
        t[:port]     = @port

        t[:db_path]        = File.expand_path( @db_path )
        t[:bookmarks_path] = File.expand_path( @bookmarks_path )
        t[:cache_path]     = File.expand_path( @cache_path )

        t[:new_book_days] = @new_book_days

        File.binwrite( @config_path, JSON.pretty_generate( t ) )

        puts "config created at #{@config_path}" if $debug
end
Also aliased as: save_config
save_config()
Alias for: save

Private Instance Methods

load() click to toggle source

load settings from json config file

# File lib/kamishibai/config.rb, line 70
def load
        json = JSON.parse( File.binread( @config_path ) )

        @srcs         = json['srcs'].collect { |src| File.expand_path(src) }
        @image_resize = json['image_resize']
        @default_image_quality = json['default_image_quality']
        @username = json['username']
        @password = json['password']
        @bind     = json['bind']
        @port     = json['port']

        @db_path         = File.expand_path( json['db_path'] )
        @bookmarks_path  = File.expand_path( json['bookmarks_path'] )
        @cache_path      = File.expand_path( json['cache_path'] )

        @new_book_days   = json['new_book_days']

        puts "config loaded at #{@config_path}" if $debug
end