Class: Boxing::Context
- Inherits:
 - 
      Object
      
        
- Object
 - Boxing::Context
 
 
- Defined in:
 - lib/boxing/context.rb
 
Overview
The template context
Instance Attribute Summary collapse
- #config ⇒ Object readonly
 
Instance Method Summary collapse
- 
  
    
      #command  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    
Return command options.
 - 
  
    
      #default_packages  ⇒ Array<Boxing::Package> 
    
    
  
  
  
  
  
  
  
  
  
    
Default packages.
 - 
  
    
      #entrypoint  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    
Return entrypoint options.
 - 
  
    
      #exclude_groups  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    
Exclude Gems in container images.
 - 
  
    
      #extra_packages  ⇒ Array<Boxing::Package> 
    
    
  
  
  
  
  
  
  
  
  
    
Extra Packages.
 - 
  
    
      #git?  ⇒ TrueClass|FalseClass 
    
    
  
  
  
  
  
  
  
  
  
    
Does any gem from git.
 - 
  
    
      #has?(*names)  ⇒ TrueClass|FalseClass 
    
    
  
  
  
  
  
  
  
  
  
    
Check rubygems exists.
 - 
  
    
      #initialize(config, database, dependencies = [])  ⇒ Context 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Context.
 - 
  
    
      #mode_of(name)  ⇒ Number 
    
    
  
  
  
  
  
  
  
  
  
    
Check Package Mode.
 - 
  
    
      #node_version  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Return node.js version.
 - 
  
    
      #packages  ⇒ Set<Boxing::Package> 
    
    
  
  
  
  
  
  
  
  
  
    
Return required packages.
 - 
  
    
      #to_binding  ⇒ Binding 
    
    
  
  
  
  
  
  
  
  
  
    
Convert to binding.
 
Constructor Details
#initialize(config, database, dependencies = []) ⇒ Context
Returns a new instance of Context.
      16 17 18 19 20 21 22  | 
    
      # File 'lib/boxing/context.rb', line 16 def initialize(config, database, dependencies = []) @config = config @database = database @dependencies = dependencies @config.port = 3000 if has?('rails') end  | 
  
Instance Attribute Details
#config ⇒ Object (readonly)
      9 10 11  | 
    
      # File 'lib/boxing/context.rb', line 9 def config @config end  | 
  
Instance Method Details
#command ⇒ Array<String>
Return command options
      147 148 149 150 151 152 153 154 155  | 
    
      # File 'lib/boxing/context.rb', line 147 def command return config.command.map(&:to_s) if config.command return ['config/environment.Lamby.cmd'] if has?('lamby') return ['config/environment.Aws::Rails::SqsActiveJob.lambda_job_handler'] if has?('aws-sdk-rails') return ['server'] if has?('openbox') return ['server', '-b', '0.0.0.0'] if has?('rails') ['rackup', '-o', '0.0.0.0'] end  | 
  
#default_packages ⇒ Array<Boxing::Package>
Default packages
      74 75 76 77 78 79 80 81  | 
    
      # File 'lib/boxing/context.rb', line 74 def default_packages [ Package.new('build-base', mode: Package::BUILD) ] .push(git? ? Package.new('git', mode: Package::BUILD) : nil) .push(has?('liveness') ? Package.new('curl', mode: Package::RUNTIME) : nil) .compact end  | 
  
#entrypoint ⇒ Array<String>
Return entrypoint options
      133 134 135 136 137 138 139 140  | 
    
      # File 'lib/boxing/context.rb', line 133 def entrypoint return config.entrypoint.map(&:to_s) if config.entrypoint return ['bin/aws_lambda_ric'] if has?('aws_lambda_ric') return ['bin/openbox'] if has?('openbox') return ['bin/rails'] if has?('rails') %w[bundle exec] end  | 
  
#exclude_groups ⇒ Array<String>
Exclude Gems in container images
      45 46 47  | 
    
      # File 'lib/boxing/context.rb', line 45 def exclude_groups @exclude_groups ||= config.exclude_groups || [] end  | 
  
#extra_packages ⇒ Array<Boxing::Package>
Extra Packages
      88 89 90 91 92 93 94  | 
    
      # File 'lib/boxing/context.rb', line 88 def extra_packages [config.build_packages, config.runtime_packages].flatten.map do |name| next if name.nil? Package.new(name, mode: mode_of(name)) end.compact end  | 
  
#git? ⇒ TrueClass|FalseClass
Does any gem from git
      65 66 67  | 
    
      # File 'lib/boxing/context.rb', line 65 def git? @dependencies.any?(&:git) end  | 
  
#has?(*names) ⇒ TrueClass|FalseClass
Check rubygems exists
      56 57 58  | 
    
      # File 'lib/boxing/context.rb', line 56 def has?(*names) @dependencies.any? { |dep| names.include?(dep.name) } end  | 
  
#mode_of(name) ⇒ Number
Check Package Mode
      121 122 123 124 125 126  | 
    
      # File 'lib/boxing/context.rb', line 121 def mode_of(name) mode = 0 mode |= Package::BUILD if config.build_packages&.include?(name) mode |= Package::RUNTIME if config.runtime_packages&.include?(name) mode end  | 
  
#node_version ⇒ String
Return node.js version
      101 102 103 104 105  | 
    
      # File 'lib/boxing/context.rb', line 101 def node_version return config.node_version if config.node_version `node -v`.gsub(/^v/, '') end  | 
  
#packages ⇒ Set<Boxing::Package>
Return required packages
      29 30 31 32 33 34 35 36 37 38  | 
    
      # File 'lib/boxing/context.rb', line 29 def packages @packages ||= Set .new(default_packages + extra_packages) .merge( @dependencies .map(&:name) .flat_map { |name| @database.package_for(name).to_a } ) end  | 
  
#to_binding ⇒ Binding
Convert to binding
      112 113 114  | 
    
      # File 'lib/boxing/context.rb', line 112 def to_binding binding end  |