lib/stove.rb in stove-1.1.2 vs lib/stove.rb in stove-2.0.0.beta.1
- old
+ new
@@ -1,27 +1,110 @@
+require 'pathname'
+
+require 'log4r'
+Log4r.define_levels(*Log4r::Log4rConfig::LogLevels)
+
module Stove
- require_relative 'stove/config'
- require_relative 'stove/git'
- require_relative 'stove/logger'
+ autoload :Config, 'stove/config'
+ autoload :Community, 'stove/community'
+ autoload :Cookbook, 'stove/cookbook'
+ autoload :Cli, 'stove/cli'
+ autoload :Error, 'stove/error'
+ autoload :Filter, 'stove/filter'
+ autoload :JIRA, 'stove/jira'
+ autoload :Mash, 'stove/mash'
+ autoload :Packager, 'stove/packager'
+ autoload :Runner, 'stove/runner'
+ autoload :Util, 'stove/util'
+ autoload :Validator, 'stove/validator'
+ autoload :VERSION, 'stove/version'
- require_relative 'stove/cli'
- require_relative 'stove/community_site'
- require_relative 'stove/cookbook'
- require_relative 'stove/error'
- require_relative 'stove/formatter'
- require_relative 'stove/github'
- require_relative 'stove/jira'
- require_relative 'stove/mash'
- require_relative 'stove/packager'
- require_relative 'stove/uploader'
- require_relative 'stove/version'
+ module Action
+ autoload :Base, 'stove/actions/base'
+ autoload :Bump, 'stove/actions/bump'
+ autoload :Changelog, 'stove/actions/changelog'
+ autoload :Dev, 'stove/actions/dev'
+ autoload :Finish, 'stove/actions/finish'
+ autoload :Start, 'stove/actions/start'
+ autoload :Upload, 'stove/actions/upload'
+ end
+ module Middleware
+ autoload :ChefAuthentication, 'stove/middlewares/chef_authentication'
+ autoload :Exceptions, 'stove/middlewares/exceptions'
+ end
+
+ module Mixin
+ autoload :Filterable, 'stove/mixins/filterable'
+ autoload :Insideable, 'stove/mixins/insideable'
+ autoload :Instanceable, 'stove/mixins/instanceable'
+ autoload :Loggable, 'stove/mixins/loggable'
+ autoload :Optionable, 'stove/mixins/optionable'
+ autoload :Validatable, 'stove/mixins/validatable'
+ end
+
+ module Plugin
+ autoload :Base, 'stove/plugins/base'
+ autoload :Git, 'stove/plugins/git'
+ autoload :GitHub, 'stove/plugins/github'
+ autoload :JIRA, 'stove/plugins/jira'
+ end
+
+ #
+ # A constant to represent an unset value. +nil+ is too generic and doesn't
+ # allow users to specify a value as +nil+. Using this constant, we can
+ # safely create +set_or_return+-style methods.
+ #
+ # @return [Object]
+ #
+ UNSET_VALUE = Object.new
+
+ #
+ # The User-Agent to use for HTTP requests
+ #
+ # @return [String]
+ #
+ USER_AGENT = "Stove #{VERSION}"
+
class << self
- def formatter
- @formatter ||= Stove::Formatter::Human.new
+ #
+ # The source root of the ChefAPI gem. This is useful when requiring files
+ # that are relative to the root of the project.
+ #
+ # @return [Pathname]
+ #
+ def root
+ @root ||= Pathname.new(File.expand_path('../../', __FILE__))
end
- def set_formatter(name)
- @formatter = Stove::Formatter::Base.formatters[name.to_sym].new
+ #
+ # The current log level for the entire application.
+ #
+ # @return [Integer]
+ #
+ def log_level
+ Log4r::Logger.global.level
end
+
+ #
+ # Set the global log level.
+ #
+ # @example Set the log level to warn
+ # Stove.log_level = :warn
+ #
+ # @param [String, Symbol] id
+ # the log level to set
+ #
+ def log_level=(id)
+ level = Log4r.const_get(id.to_s.upcase)
+ raise NameError unless level.is_a?(Integer)
+
+ Log4r::Logger.global.level = level
+ rescue NameError
+ $stderr.puts "ERROR `#{id}' is not a valid Log Level!"
+ end
end
end
+
+require 'i18n'
+I18n.enforce_available_locales = true
+I18n.load_path << Dir[Stove.root.join('locales', '*.yml').to_s]