Class: Ore::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/ore/options.rb

Overview

Value object to contain ~/.ore/options.yml data.

Since:

  • 0.11.0

Constant Summary collapse

DEFAULT_MARKUP =

Default markup

Since:

  • 0.11.0

'markdown'
DEFAULT_VERSION =

Default version

Since:

  • 0.11.0

'0.1.0'
DEFAULT_SUMMARY =

Default summary

Since:

  • 0.11.0

%q{TODO: Summary}
DEFAULT_DESCRIPTION =

Default description

Since:

  • 0.11.0

%q{TODO: Description}
DEFAULT_TEMPLATES =

Default templates

Since:

  • 0.11.0

[
  :git,
  :mit,
  :bundler,
  :rubygems_tasks,
  :rdoc,
  :rspec
]
DEFAULTS =

Default options

Since:

  • 0.11.0

{
  markup:      DEFAULT_MARKUP,
  version:     DEFAULT_VERSION,
  summary:     DEFAULT_SUMMARY,
  description: DEFAULT_DESCRIPTION
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Options

Initializes the options.

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

    The options hash.

Since:

  • 0.11.0


48
49
50
# File 'lib/ore/options.rb', line 48

def initialize(options={})
  @options = DEFAULTS.merge(options)
end

Class Method Details

.load(path) ⇒ Options

Loads the options from a YAML file.

Parameters:

  • path (String)

    Path to the options file.

Returns:

  • (Options)

    The loaded options.

Raises:

  • (RuntimeError)

    The file contained malformed YAML.

Since:

  • 0.11.0


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ore/options.rb', line 64

def self.load(path)
  data = YAML.load_file(path)

  unless data.kind_of?(Hash)
    raise("#{path} must contain a YAML encoded Hash")
  end

  options = {}

  data.each do |key,value|
    options[key.to_sym] = value
  end

  return new(options)
end

Instance Method Details

#[](key) ⇒ Object

Accesses an option.

Parameters:

  • key (Symbol)

    The option name.

Returns:

  • (Object)

    The option value.

Since:

  • 0.11.0


89
90
91
# File 'lib/ore/options.rb', line 89

def [](key)
  @options[key]
end