Class: Crudboy::App
Class Attribute Summary collapse
-
.connect_options ⇒ Object
Returns the value of attribute connect_options.
-
.env ⇒ Object
Returns the value of attribute env.
-
.instance ⇒ Object
Returns the value of attribute instance.
-
.prompt ⇒ Object
Returns the value of attribute prompt.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #connect_options ⇒ Object
- #effective_config ⇒ Object
-
#initialize(options) ⇒ App
constructor
A new instance of App.
- #load_initializer! ⇒ Object
- #run! ⇒ Object
- #selected_config ⇒ Object
- #start_ssh_proxy! ⇒ Object
Constructor Details
#initialize(options) ⇒ App
Returns a new instance of App.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/crudboy/app.rb', line 14 def initialize() require 'active_support/all' require 'active_record' require 'composite_primary_keys' require "crudboy/connection" require "crudboy/definition" @options = App.env = @options.env App. = Connection.open(App.) @definition = Definition.new(effective_config) @context = TemplateContext.new(@definition) load_initializer! App.instance = self end |
Class Attribute Details
.connect_options ⇒ Object
Returns the value of attribute connect_options.
7 8 9 |
# File 'lib/crudboy/app.rb', line 7 def @connect_options end |
.env ⇒ Object
Returns the value of attribute env.
7 8 9 |
# File 'lib/crudboy/app.rb', line 7 def env @env end |
.instance ⇒ Object
Returns the value of attribute instance.
7 8 9 |
# File 'lib/crudboy/app.rb', line 7 def instance @instance end |
.prompt ⇒ Object
Returns the value of attribute prompt.
7 8 9 |
# File 'lib/crudboy/app.rb', line 7 def prompt @prompt end |
Class Method Details
.config ⇒ Object
9 10 11 |
# File 'lib/crudboy/app.rb', line 9 def config @@effective_config end |
Instance Method Details
#config ⇒ Object
65 66 67 68 69 |
# File 'lib/crudboy/app.rb', line 65 def config @config ||= YAML.load(IO.read(File.(@options.config_file)), aliases: true).with_indifferent_access rescue ArgumentError @config ||= YAML.load(IO.read(File.(@options.config_file))).with_indifferent_access end |
#connect_options ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/crudboy/app.rb', line 30 def connect_conf = effective_config.slice(:adapter, :host, :username, :password, :database, :encoding, :pool, :port, :socket) if effective_config[:ssh].present? connect_conf.merge!(start_ssh_proxy!) end connect_conf end |
#effective_config ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/crudboy/app.rb', line 82 def effective_config @@effective_config ||= nil unless @@effective_config @@effective_config = selected_config.deep_merge(@options.to_h) if @@effective_config[:adapter].blank? @@effective_config[:adapter] = 'sqlite3' end @@effective_config[:database] = File.(@@effective_config[:database]) if @@effective_config[:adapter] == 'sqlite3' end @@effective_config end |
#load_initializer! ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/crudboy/app.rb', line 41 def load_initializer! return unless effective_config[:initializer] initializer_file = File.(effective_config[:initializer]) unless File.exists?(initializer_file) STDERR.puts "Specified initializer file not found, #{effective_config[:initializer]}" exit(1) end load(initializer_file) end |
#run! ⇒ Object
94 95 96 |
# File 'lib/crudboy/app.rb', line 94 def run! Bundle.new(@options.template_bundle, @options.template_args, @options.destination, @context).render! end |
#selected_config ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/crudboy/app.rb', line 71 def selected_config if @options.env.present? && !config[@options.env].present? STDERR.puts "Specified ENV `#{@options.env}' not exists" end if env = @options.env config[env] else {} end end |
#start_ssh_proxy! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/crudboy/app.rb', line 51 def start_ssh_proxy! ssh_config = effective_config[:ssh] local_ssh_proxy_port = Crudboy::SSHProxy.connect( ssh_config.slice(:host, :user, :port, :password).merge( forward_host: effective_config[:host], forward_port: effective_config[:port], local_port: ssh_config[:local_port])) { host: '127.0.0.1', port: local_ssh_proxy_port } end |