Class: Furoshiki::Configuration

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/furoshiki/configuration.rb

Overview

Configuration for Furoshiki packagers.

If your configuration uses hashes, the keys will always be symbols, even if you have created it with string keys. It’s just easier that way.

This is a value object. If you need to modify your configuration after initialization, dump it with #to_hash, make your changes, and instantiate a new object.

Constant Summary collapse

JAR_APP_TEMPLATE_URL =
'https://s3.amazonaws.com/net.wasnotrice.shoes/wrappers/shoes-app-template-0.0.2.zip'

Instance Method Summary collapse

Methods included from Util

#deep_set_symbol_key, #deep_symbolize_keys, #merge_with_symbolized_keys

Constructor Details

#initialize(config = {}) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • config (Hash) (defaults to: {})

    user options

  • working_dir (String)

    directory in which to do packaging work



24
25
26
27
28
# File 'lib/furoshiki/configuration.rb', line 24

def initialize(config = {})
  merge_config config
  sanitize_config
  define_readers
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
62
# File 'lib/furoshiki/configuration.rb', line 59

def ==(other)
  super unless other.class == self.class && other.respond_to?(:to_hash)
  @config == other.to_hash && working_dir == other.working_dir
end

#error_message_listObject



55
56
57
# File 'lib/furoshiki/configuration.rb', line 55

def error_message_list
  validator.error_message_list
end

#shortnameObject



30
31
32
# File 'lib/furoshiki/configuration.rb', line 30

def shortname
  @config[:shortname] || name.downcase.gsub(/\W+/, '')
end

#to_hashObject



42
43
44
# File 'lib/furoshiki/configuration.rb', line 42

def to_hash
  @config
end

#to_warbler_configObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/furoshiki/configuration.rb', line 64

def to_warbler_config
  warbler_config = nil
  Dir.chdir working_dir do
    warbler_config = Warbler::Config.new do |config|
      config.jar_name = self.shortname
      specs = self.gems.map do |gem|
        # This is rather a hack as  Gem::Specification.find_by_name(gem)
        # seems to break Travis.
        # See: https://github.com/shoes/shoes4/pull/989#issuecomment-68170746
        Gem::Specification.find_all_by_name(gem).first
      end
      dependencies = specs.map { |s| s.runtime_dependencies }.flatten
      (specs + dependencies).uniq.each { |g| config.gems << g }
      ignore = self.ignore.map do |f|
        path = f.to_s
        children = Dir.glob("#{path}/**/*") if File.directory?(path)
        [path, *children]
      end.flatten
      config.gem_excludes += [/^samples/, /^examples/, /^test/, /^spec/]

      warbler_extensions.customize(config) if warbler_extensions.respond_to? :customize

      # Important this is after extensions can alter pathmaps.application
      config.excludes.add FileList.new(ignore.flatten).pathmap(config.pathmaps.application.first)
    end
  end
  warbler_config
end

#valid?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/furoshiki/configuration.rb', line 46

def valid?
  validator.valid?
end

#validateObject



50
51
52
53
# File 'lib/furoshiki/configuration.rb', line 50

def validate
  return unless validator.respond_to? :reset_and_validate
  validator.reset_and_validate
end

#validatorObject



34
35
36
# File 'lib/furoshiki/configuration.rb', line 34

def validator
  @validator ||= validator_class.new(self)
end

#warbler_extensionsObject



38
39
40
# File 'lib/furoshiki/configuration.rb', line 38

def warbler_extensions
  @warbler_extensions ||= warbler_extensions_class.new(self)
end