Class: Autoversion::DSL
- Inherits:
-
Object
- Object
- Autoversion::DSL
- Defined in:
- lib/autoversion/dsl.rb
Defined Under Namespace
Classes: InvalidGitConfig, MissingReadBlock
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#listeners ⇒ Object
Returns the value of attribute listeners.
-
#read_blk ⇒ Object
Returns the value of attribute read_blk.
-
#write_blk ⇒ Object
Returns the value of attribute write_blk.
Class Method Summary collapse
Instance Method Summary collapse
-
#after(event, &blk) ⇒ Object
Register a block that will be executed after a certain event has fired.
- #automate_git(*args) ⇒ Object
-
#before(event, &blk) ⇒ Object
Register a block that will be executed before a certain event has fired.
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
-
#read_version(&blk) ⇒ Object
Register a block that will be used to read the version number from the current project.
- #validate! ⇒ Object
-
#write_version(&blk) ⇒ Object
Register a block that will be used to write the version number to the current project.
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/autoversion/dsl.rb', line 15 def initialize @read_blk = nil @write_blk = nil @listeners = [] @config = { :git => { :actions => [], :prefix => '', :stable_branch => 'master' } } end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/autoversion/dsl.rb', line 13 def config @config end |
#listeners ⇒ Object
Returns the value of attribute listeners.
12 13 14 |
# File 'lib/autoversion/dsl.rb', line 12 def listeners @listeners end |
#read_blk ⇒ Object
Returns the value of attribute read_blk.
10 11 12 |
# File 'lib/autoversion/dsl.rb', line 10 def read_blk @read_blk end |
#write_blk ⇒ Object
Returns the value of attribute write_blk.
11 12 13 |
# File 'lib/autoversion/dsl.rb', line 11 def write_blk @write_blk end |
Class Method Details
.evaluate(script) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/autoversion/dsl.rb', line 79 def evaluate(script) obj = self.new obj.instance_eval(script) obj.validate! return obj.read_blk, obj.write_blk, obj.listeners, obj.config end |
Instance Method Details
#after(event, &blk) ⇒ Object
Register a block that will be executed after a certain event has fired.
60 61 62 63 64 65 66 |
# File 'lib/autoversion/dsl.rb', line 60 def after event, &blk @listeners.push({ :type => :after, :event => event, :blk => blk }) end |
#automate_git(*args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/autoversion/dsl.rb', line 34 def automate_git *args if args.length == 0 @config[:git][:actions] = [:commit, :tag] else args[0].each do |arg| if [:actions, :stable_branch, :prefix].include?(arg[0]) @config[:git][arg[0]] = arg[1] end end end end |
#before(event, &blk) ⇒ Object
Register a block that will be executed before a certain event has fired.
70 71 72 73 74 75 76 |
# File 'lib/autoversion/dsl.rb', line 70 def before event, &blk @listeners.push({ :type => :before, :event => event, :blk => blk }) end |
#read_version(&blk) ⇒ Object
Register a block that will be used to read the version number from the current project.
48 49 50 |
# File 'lib/autoversion/dsl.rb', line 48 def read_version &blk @read_blk = blk end |
#validate! ⇒ Object
28 29 30 31 32 |
# File 'lib/autoversion/dsl.rb', line 28 def validate! # A read_version block is required raise MissingReadBlock unless @read_blk raise InvalidGitConfig if @config[:git][:actions].include?(:tag) && !@config[:git][:actions].include?(:commit) end |
#write_version(&blk) ⇒ Object
Register a block that will be used to write the version number to the current project.
54 55 56 |
# File 'lib/autoversion/dsl.rb', line 54 def write_version &blk @write_blk = blk end |