import popcorn
import popcorn::pop_config
# Build config from default values
var config = new AppConfig
config.parse_options(args)
# Change config values
config.ini["app.port"] = 3001.to_s
# Use options
var app = new App
app.listen(config.app_host, config.app_port)
popcorn :: AppConfig :: default_db_host
Default database host string for MongoDbpopcorn :: AppConfig :: default_db_host=
Default database host string for MongoDbpopcorn :: AppConfig :: default_db_name=
Default database hostnamepopcorn :: AppConfig :: defaultinit
popcorn :: AppConfig :: opt_db_host=
MongoDb host namepopcorn :: AppConfig :: opt_db_name=
MongoDb database namepopcorn :: AppConfig :: opt_host
Host name to bind on (will overwrite the config one).popcorn :: AppConfig :: opt_host=
Host name to bind on (will overwrite the config one).popcorn :: AppConfig :: opt_hostname=
Displayed host namepopcorn :: AppConfig :: tracker_logs=
Logs collectionpopcorn $ AppConfig :: default_config_file
Default config file pathpopcorn $ AppConfig :: default_config_file=
Default config file pathcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
config :: IniConfig :: config_file
Return the config file path from options or the defaultconfig :: IniConfig :: default_config_file=
Default config file pathpopcorn :: AppConfig :: default_db_host
Default database host string for MongoDbpopcorn :: AppConfig :: default_db_host=
Default database host string for MongoDbpopcorn :: AppConfig :: default_db_name=
Default database hostnamepopcorn :: AppConfig :: defaultinit
core :: Object :: defaultinit
config :: Config :: defaultinit
config :: IniConfig :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
config :: Config :: opt_black_exts=
--blacklist-extsconfig :: Config :: opt_black_exts=
--blacklist-extsconfig :: IniConfig :: opt_config=
Path to app config filepopcorn :: AppConfig :: opt_db_host=
MongoDb host namepopcorn :: AppConfig :: opt_db_name=
MongoDb database namepopcorn :: AppConfig :: opt_host
Host name to bind on (will overwrite the config one).popcorn :: AppConfig :: opt_host=
Host name to bind on (will overwrite the config one).popcorn :: AppConfig :: opt_hostname=
Displayed host nameconfig :: Config :: opt_java_cp
config :: Config :: opt_java_cp=
config :: Config :: opt_stub_man=
Option --stub-manconfig :: Config :: opt_white_exts=
--whitelist-extsconfig :: Config :: opt_white_exts=
--whitelist-extscore :: Object :: output_class_name
Display class name on stdout (debug only).config :: Config :: parse_options
Initializeself
options from args
config :: Config :: tool_description
Name, usage and synopsis of the tool.config :: Config :: tool_description=
Name, usage and synopsis of the tool.popcorn :: AppConfig :: tracker_logs=
Logs collection
# Configuration file for Popcorn apps
#
# ~~~
# import popcorn
# import popcorn::pop_config
#
# # Build config from default values
# var config = new AppConfig
# config.parse_options(args)
#
# # Change config values
# config.ini["app.port"] = 3001.to_s
#
# # Use options
# var app = new App
# app.listen(config.app_host, config.app_port)
# ~~~
class AppConfig
super IniConfig
redef var default_config_file: String = "app.ini"
# Host name to bind on (will overwrite the config one).
var opt_host = new OptionString("Host to bind the server on", "--host")
# Web app host name
#
# * key: `app.host`
# * default: `localhost`
fun app_host: String do return opt_host.value or else ini["app.host"] or else "localhost"
# Port number to bind on (will overwrite the config one).
var opt_port = new OptionInt("Port number to use", -1, "--port")
# Web app port
#
# * key: `app.port`
# * default: `3000`
fun app_port: Int do
var opt = opt_port.value
if opt > -1 then return opt
var val = ini["app.port"]
if val != null then return val.to_i
return 3000
end
# Displayed host name
#
# Specify this option if you need a qualified hostname to use within your handlers
# and `app_host` requires something else like an IP to bind.
# Really useful if the popcorn app runs behind a proxy.
#
# Default is `"{app_host}:{app_port}"`
var opt_hostname = new OptionString("Displayed host name", "--hostname")
# Displayed host name config
#
# * key: `app.hostname`
# * default: `"{app_host}:{app_port}"`
fun app_hostname: String do
var opt = opt_hostname.value
if opt != null then return opt
var cfg = ini["app.hostname"]
if cfg != null then return cfg
var res = app_host
if app_port != 80 then res = "{res}:{app_port}"
return res
end
init do
super
add_option(opt_host, opt_port, opt_hostname)
end
end
lib/popcorn/pop_config.nit:82,1--155,3
redef class AppConfig
# Default database host string for MongoDb
var default_db_host = "mongodb://mongo:27017/"
# Default database hostname
var default_db_name = "popcorn"
# MongoDb host name
var opt_db_host = new OptionString("MongoDb host", "--db-host")
# MongoDb database name
var opt_db_name = new OptionString("MongoDb database name", "--db-name")
# MongoDB server used for data persistence
fun db_host: String do return opt_db_host.value or else ini["db.host"] or else default_db_host
# MongoDB DB used for data persistence
fun db_name: String do return opt_db_name.value or else ini["db.name"] or else default_db_name
init do
super
add_option(opt_db_host, opt_db_name)
end
# Mongo db client
var client = new MongoClient(db_host) is lazy
# Mongo db instance
var db: MongoDb = client.database(db_name) is lazy
end
lib/popcorn/pop_repos.nit:126,1--156,3
redef class AppConfig
# Logs collection
var tracker_logs = new TrackerRepo(db.collection("tracker_logs"))
# Tracker handler
var tracker = new PopTracker(self)
end
lib/popcorn/pop_tracker.nit:52,1--59,3