Skip to content

TemaMix/dsl_organizer

Repository files navigation

DslOrganizer Build Status Code Climate

DslOrganizer provides a simple way to create self dsl and allows to integrate dsl to logic easy.

Installation

Installation is pretty standard:

$ gem install dsl_organizer

If you use bundler to add it to your Gemfile:

gem 'dsl_organizer', '~> 1.0'

And then execute:

$ bundle

Usage

Brief Example

  1. Firstly, you should think up commands for your dsl.
module Configuration
 include DslOrganizer.dictionary(
   commands: [:font_colors, :backgrounds]
  )
end
  1. Secondly, you should define executors for your commands and export them.
class FontColorExecutor
  include DslOrganizer::ExportCommand[:font_colors]
  
  def call(font_color)
     colors << font_color
  end
  
  def colors
     @colors ||= []
  end
end

class BackroundExecutor
  include DslOrganizer::ExportCommand[:backgrounds]
  
  def call(backround_color)
     colors << backround_color
  end
  
  def colors
     @colors ||= []
  end
end
  1. Thirdly, described logic with using dsl commands can look something like that:
Configuration.run do
 font_colors'#AAA'
 font_colors '#BBB'
 backgrounds '#CCC'
end

The dsl commands color and background will executed immediately.

  1. Finally, you can integrate commands to basic logic to use for it the Dependency Injection pattern:
module Configuration
 def self.print_all_colors
   dsl_container[:font_colors].colors.map do |color|
     puts color
   end
   
   dsl_container[:backgrounds].colors.map do |color|
     puts color
   end
 end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/temamix/dsl_organizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

About

Allows to add a simple DSL to object.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages