Class: Kompo::Option

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/kompo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = Dir.getwd, opt = OptionParser.new) ⇒ Option

Returns a new instance of Option.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kompo.rb', line 18

def initialize(dir = Dir.getwd, opt = OptionParser.new)
  @entrypoint = File.join(dir, 'main.rb')
  @output = File.basename(dir)
  @gemfile = File.exist?(File.join(Dir.getwd, 'Gemfile'))
  @ignore_stdlib = []
  @dyn_link_lib = []
  @dest_dir = dir
  @ruby_src_path = nil
  @cache_bundle_path = nil
  @ruby_version = "v#{RUBY_VERSION.gsub('.', '_')}"
  @compress = false
  @use_group = 'default'

  @context = dir
  @opt = opt
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



15
16
17
# File 'lib/kompo.rb', line 15

def args
  @args
end

#cache_bundle_pathObject

Returns the value of attribute cache_bundle_path.



15
16
17
# File 'lib/kompo.rb', line 15

def cache_bundle_path
  @cache_bundle_path
end

#compressObject

Returns the value of attribute compress.



15
16
17
# File 'lib/kompo.rb', line 15

def compress
  @compress
end

#contextObject

Returns the value of attribute context.



15
16
17
# File 'lib/kompo.rb', line 15

def context
  @context
end

#dest_dirObject

Returns the value of attribute dest_dir.



15
16
17
# File 'lib/kompo.rb', line 15

def dest_dir
  @dest_dir
end

Returns the value of attribute dyn_link_lib.



15
16
17
# File 'lib/kompo.rb', line 15

def dyn_link_lib
  @dyn_link_lib
end

#entrypointObject

Returns the value of attribute entrypoint.



15
16
17
# File 'lib/kompo.rb', line 15

def entrypoint
  @entrypoint
end

#gemfileObject

Returns the value of attribute gemfile.



15
16
17
# File 'lib/kompo.rb', line 15

def gemfile
  @gemfile
end

#ignore_stdlibObject

Returns the value of attribute ignore_stdlib.



15
16
17
# File 'lib/kompo.rb', line 15

def ignore_stdlib
  @ignore_stdlib
end

#outputObject

Returns the value of attribute output.



15
16
17
# File 'lib/kompo.rb', line 15

def output
  @output
end

#ruby_src_pathObject

Returns the value of attribute ruby_src_path.



15
16
17
# File 'lib/kompo.rb', line 15

def ruby_src_path
  @ruby_src_path
end

#ruby_versionObject

Returns the value of attribute ruby_version.



15
16
17
# File 'lib/kompo.rb', line 15

def ruby_version
  @ruby_version
end

#use_groupObject

Returns the value of attribute use_group.



15
16
17
# File 'lib/kompo.rb', line 15

def use_group
  @use_group
end

Class Method Details

.defaultObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kompo.rb', line 35

def self.default
  option = new
  option.on('-e VAL', '--entrypoint=VAL', "File path to use for entry point. (default: \'./main.rb\')") { |v| option.entrypoint = v }
  option.on('-o VAL', '--output=VAL', 'Name of the generated file. (default: current dir name)') { |v| option.output = v }
  option.on('-g VAL', '--use-group=VAL', "Group name to use with \'bundle install\'. (default: \'default\')") { |v| option.use_group = v }
  option.on('--[no-]gemfile', "Use gem in Gemfile. (default: automatically true if Gemfile is present)") { |v| option.gemfile = v }
  option.on('--ignore-stdlib=VAL', Array, "Specify stdlibs not to include, separated by commas.") { |v| option.ignore_stdlib = v }
  option.on('--dyn-link-lib=VAL', Array, "Specify libraries to be dynamic link, separated by commas.") { |v| option.dyn_link_lib = v }
  option.on('--dest-dir=VAL', "Output directry path. (default: current dir)") { |v| option.dest_dir = v }
  option.on('--ruby-src-path=VAL', "Your Ruby source directry. Must be compiled with \'--with-static-linked-ext\'.") { |v| option.ruby_src_path = v }
  option.on('--cache-bundle-path=VAL', "Specify the directory created by \'bundle install --standalone\'.") { |v| option.cache_bundle_path = v }
  option.on('--ruby-version=VAL', "Specify Ruby version. (default: current Ruby version)") { |v| option.ruby_version = v }
  # option.on('--compress') { |v| option.compress = v }

  option
end

Instance Method Details

#buildObject



52
53
54
55
56
57
58
# File 'lib/kompo.rb', line 52

def build
  @opt.parse!(ARGV)

  @args = convert_absolute_path_for ARGV

  self
end