Class: GitShizzle::Dsl::CommandCollection
- Inherits:
-
Object
- Object
- GitShizzle::Dsl::CommandCollection
- Defined in:
- lib/git_shizzle/dsl/command_collection.rb
Instance Method Summary collapse
- #add_command(command) ⇒ Object
- #each(&block) ⇒ Object
- #find(identifier) ⇒ Object
-
#initialize ⇒ CommandCollection
constructor
A new instance of CommandCollection.
- #load(contents = nil) ⇒ Object
Constructor Details
#initialize ⇒ CommandCollection
Returns a new instance of CommandCollection.
5 6 7 |
# File 'lib/git_shizzle/dsl/command_collection.rb', line 5 def initialize @commands = [] end |
Instance Method Details
#add_command(command) ⇒ Object
9 10 11 12 13 |
# File 'lib/git_shizzle/dsl/command_collection.rb', line 9 def add_command(command) raise DuplicateCommandDefinitionError.new(command) if @commands.any? { |c| c.identifier == command.identifier} @commands << command end |
#each(&block) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/git_shizzle/dsl/command_collection.rb', line 31 def each(&block) @commands.each do |command| if block_given? block.call command else yield command end end end |
#find(identifier) ⇒ Object
41 42 43 |
# File 'lib/git_shizzle/dsl/command_collection.rb', line 41 def find(identifier) @commands.find { |c| c.identifier == identifier } or raise GitShizzle::Dsl::CommandNotFoundError.new(identifier) end |
#load(contents = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/git_shizzle/dsl/command_collection.rb', line 15 def load(contents = nil) data = contents unless data filenames = ['commands', 'Commands', 'commands.rb', 'Commands.rb'].map do |f| "#{File.dirname(__FILE__)}/../../#{f}" end filename = filenames.find { |f| File.file?(f) } raise GitShizzle::Dsl::NoCommandFileFoundError.new if filename.nil? data = File.read(filename) end dsl.instance_eval(data, "./#{filename}") end |