Class: DotRuby::DSL
- Inherits:
- BasicObject
- Includes:
- Kernel
- Defined in:
- lib/dotruby/dsl.rb
Overview
DotRuby DSL class is used to evaluate the ‘.ruby` configuration file.
Instance Attribute Summary collapse
-
#file ⇒ String
readonly
The path of the current project’s ‘.ruby` file.
Class Method Summary collapse
-
.const_missing(cname) ⇒ Constant
Constants provide configuration.
Instance Method Summary collapse
-
#constants ⇒ Hash
Table of constant configurations.
-
#default_tag(cname, command, feature = nil) ⇒ Hash<Array>
Set the default tag for a constant.
-
#environment(matches = {}, &block) ⇒ Object
Only configure if environment matches.
-
#import(name, options = {}) ⇒ Object
Import configuration from an external source.
-
#initialize(file) ⇒ DSL
constructor
Initialize new DSL instance.
-
#profile(match, &block) ⇒ Object
Only configure if profile matches.
-
#tag(constant, *target) ⇒ Object
Tag a constant to a command and/or feature.
-
#tags ⇒ Hash
Return recognizes tags.
Constructor Details
#initialize(file) ⇒ DSL
Initialize new DSL instance.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dotruby/dsl.rb', line 10 def initialize(file) @file = file @@default_tags ||= {} @@defined_tags ||= {} @@contants ||= {} instance_eval(::File.read(file), file) end |
Instance Attribute Details
#file ⇒ String (readonly)
The path of the current project’s ‘.ruby` file.
24 25 26 |
# File 'lib/dotruby/dsl.rb', line 24 def file @file end |
Class Method Details
Instance Method Details
#constants ⇒ Hash
Table of constant configurations.
47 48 49 |
# File 'lib/dotruby/dsl.rb', line 47 def constants @@contants end |
#default_tag(cname, command, feature = nil) ⇒ Hash<Array>
Set the default tag for a constant. Unlike defined tags, there can be only one associate for a default tag.
71 72 73 |
# File 'lib/dotruby/dsl.rb', line 71 def default_tag(cname, command, feature=nil) @@default_tags[cname.to_sym] = [command.to_s, (feature || command).to_s] end |
#environment(matches = {}, &block) ⇒ Object
Should it be logical-or or logical-and?
Only configure if environment matches.
97 98 99 100 101 |
# File 'lib/dotruby/dsl.rb', line 97 def environment(matches={}, &block) if matches.any?{ |e, m| m === ENV[e] } block.call end end |
#import(name, options = {}) ⇒ Object
Import configuration from an external source.
108 109 110 |
# File 'lib/dotruby/dsl.rb', line 108 def import(name, ={}) raise 'import is not implemented yet' end |
#profile(match, &block) ⇒ Object
Only configure if profile matches.
82 83 84 85 86 |
# File 'lib/dotruby/dsl.rb', line 82 def profile(match, &block) if match === (ENV['profile'] || ENV['p']) block.call end end |
#tag(constant, *target) ⇒ Object
Tag a constant to a command and/or feature.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dotruby/dsl.rb', line 53 def tag(constant, *target) = (::Hash === target.last ? target.pop : {}) target = target.first command = [:command] || target feature = [:feature] || target tag = [command.to_s, feature.to_s] @@defined_tags[constant] ||= [] @@defined_tags[constant] << tag unless @@defined_tags[constant].include?(tag) @@defined_tags end |
#tags ⇒ Hash
Return recognizes tags.
29 30 31 32 33 34 35 36 |
# File 'lib/dotruby/dsl.rb', line 29 def keys = @@default_tags.keys - @@defined_tags.keys = @@defined_tags.dup keys.each do |key| [key] = [@@default_tags[key]] end end |