lib/cogy.rb in cogy-0.1.1 vs lib/cogy.rb in cogy-0.2.0

- old
+ new

@@ -10,39 +10,42 @@ # Holds all the registered {Command} objects. Not to be messed with. @@commands = {} mattr_accessor :commands - # The Cog bundle name. + # Configuration related to the Cog bundle. Used in {Cogy.bundle_config} + # in order to generate the bundle config YAML. # - # Used by {Cogy.bundle_config}. - @@bundle_name = "cogy" - mattr_accessor :bundle_name + # @see https://cog-book.operable.io/#_the_config_file + @@bundle = { + # The bundle name + name: "cogy", - # The Cog bundle description. - # - # Used by {Cogy.bundle_config}. - @@bundle_description = "Cogy-generated commands" - mattr_accessor :bundle_description + # The bundle description + description: "Cog commands generated from Cogy", - # The Cog bundle version. Can be either a string or an object that responds - # to `#call` and returns a string. Used by {Cogy.bundle_config}. - # - # Used by {Cogy.bundle_config}. - # - # @example - # bundle_version = -> { rand(2).to_s } - @@bundle_version = "0.0.1" - mattr_accessor :bundle_version + # The bundle version. + # + # Can also be an object that responds to `#call` and returns a string. For + # example: + # + # -> { rand(1).to_s } + # + version: "0.0.1", - # The path in the Cog Relay where the cogy executable - # (ie. https://github.com/skroutz/cogy-bundle/blob/master/commands/cogy) is - # located. + # The path in the Cog Relay where the cogy executable + # (ie. https://github.com/skroutz/cogy-bundle/blob/master/commands/cogy) is + # located. + cogy_executable: "/usr/bin/cogy" + } + mattr_accessor :bundle + + # The Cog templates. Used in {Cogy.bundle_config}. # - # Used by {Cogy.bundle_config}. - @@executable_path = "/usr/bin/cogy" - mattr_accessor :executable_path + # @see https://cog-book.operable.io/#_templates + @@templates = {} + mattr_accessor :templates # Paths where the files that define the commands will be searched in the # host application. @@command_load_paths = ["cogy"] mattr_accessor :command_load_paths @@ -99,28 +102,28 @@ # Generates the bundle config # # @return [Hash] def self.bundle_config - version = if bundle_version.respond_to?(:call) - bundle_version.call + version = if bundle[:version].respond_to?(:call) + bundle[:version].call else - bundle_version + bundle[:version] end config = { "cog_bundle_version" => COG_BUNDLE_VERSION, - "name" => bundle_name, - "description" => bundle_description, + "name" => bundle[:name], + "description" => bundle[:description], "version" => version } config["commands"] = {} if commands.present? commands.each do |name, cmd| config["commands"][name] = { - "executable" => executable_path, + "executable" => bundle[:cogy_executable], "description" => cmd.desc, "rules" => cmd.rules } if !cmd.args.empty? @@ -138,21 +141,21 @@ if cmd.examples config["commands"][name]["examples"] = cmd.examples end end + config["templates"] = templates if !templates.empty? + config end # Configures Cogy according to the passed block. # - # @example - # Cogy.configure do |c| - # c.bundle_name = "foo" - # end - # # @yield [self] yields {Cogy} + # # @return [void] + # + # @see https://github.com/skroutz/cogy#configuration def self.configure yield self end # Defines a user helper method that can be used throughout commands.