Class: VagrantBindfs::Bindfs::OptionSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/vagrant-bindfs/bindfs/option_set.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version = nil, options = {}) ⇒ OptionSet

Returns a new instance of OptionSet.



17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 17

def initialize(version = nil, options = {})
  @version = version
  @options = normalize_option_names(options)
  @invalid_options = {}
  @unsupported_options = {}

  extract_invalid_options!
  extract_unsupported_options!
  cast_option_values!
end

Instance Attribute Details

#invalid_optionsObject (readonly)

Returns the value of attribute invalid_options.



8
9
10
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 8

def invalid_options
  @invalid_options
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 8

def options
  @options
end

#unsupported_optionsObject (readonly)

Returns the value of attribute unsupported_options.



8
9
10
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 8

def unsupported_options
  @unsupported_options
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 8

def version
  @version
end

Class Method Details

.bindfs_optionsObject



107
108
109
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 107

def bindfs_options
  @bindfs_options ||= JSON.parse(File.read(File.expand_path('option_definitions.json', __dir__)))
end

.compatible_name_for_version(option_name, version) ⇒ Object



118
119
120
121
122
123
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 118

def compatible_name_for_version(option_name, version)
  return 'user' if option_name == 'force-user' && version_lower_than(version, '1.12')
  return 'group' if option_name == 'force-group' && version_lower_than(version, '1.12')

  option_name
end

.supported_options(version) ⇒ Object



111
112
113
114
115
116
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 111

def supported_options(version)
  bindfs_options.each_with_object({}) do |(name, definition), supported|
    supported[name] = definition if version.nil? || !version_lower_than(version, definition['since'])
    supported
  end
end

Instance Method Details

#merge(other) ⇒ Object



37
38
39
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 37

def merge(other)
  dup.tap { |result| result.merge!(other) }
end

#merge!(other) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 28

def merge!(other)
  other = other.to_version(version) if other.respond_to?(:to_version)
  @options.merge!(normalize_option_names(other))

  extract_invalid_options!
  extract_unsupported_options!
  cast_option_values!
end

#to_version(new_version) ⇒ Object



41
42
43
# File 'lib/vagrant-bindfs/bindfs/option_set.rb', line 41

def to_version(new_version)
  self.class.new(new_version, @options.merge(invalid_options).merge(unsupported_options))
end