Class: Babushka::MetaDep
- Inherits:
-
Object
- Object
- Babushka::MetaDep
- Includes:
- LogHelpers
- Defined in:
- lib/babushka/meta_dep.rb
Constant Summary
- INVALID_NAMES =
%w[base]
- VALID_NAME_START_CHARS =
/[a-z]/- VALID_NAME_CHARS =
/#{VALID_NAME_START_CHARS}[a-z0-9_]*/- VALID_NAME_START =
/^#{VALID_NAME_START_CHARS}/- VALID_NAME =
/\A#{VALID_NAME_CHARS}\z/m- TEMPLATE_NAME_MATCH =
/\A.+\.(#{VALID_NAME_CHARS})\z/m
Instance Attribute Summary (collapse)
-
- (Object) context_class
readonly
Returns the value of attribute context_class.
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) opts
readonly
Returns the value of attribute opts.
-
- (Object) source
readonly
Returns the value of attribute source.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) build_context(block)
-
- (Object) contextual_name
Returns this template's name, including the source name as a prefix if this template is in a cloneable source.
- - (Object) desc
-
- (MetaDep) initialize(name, source, opts, &block)
constructor
A new instance of MetaDep.
Methods included from LogHelpers
#debug, #log, #log_block, #log_error, #log_ok, #log_verbose, #log_warn
Constructor Details
- (MetaDep) initialize(name, source, opts, &block)
A new instance of MetaDep
36 37 38 39 40 41 |
# File 'lib/babushka/meta_dep.rb', line 36 def initialize name, source, opts, &block @name, @source, @opts, @block = name, source, opts, block debug "Defining #{source.name}:#{name} template" @context_class = build_context block source.templates.register self end |
Instance Attribute Details
- (Object) context_class (readonly)
Returns the value of attribute context_class
32 33 34 |
# File 'lib/babushka/meta_dep.rb', line 32 def context_class @context_class end |
- (Object) name (readonly)
Returns the value of attribute name
32 33 34 |
# File 'lib/babushka/meta_dep.rb', line 32 def name @name end |
- (Object) opts (readonly)
Returns the value of attribute opts
32 33 34 |
# File 'lib/babushka/meta_dep.rb', line 32 def opts @opts end |
- (Object) source (readonly)
Returns the value of attribute source
32 33 34 |
# File 'lib/babushka/meta_dep.rb', line 32 def source @source end |
Class Method Details
+ (Object) for(supplied_name, source, opts, &block)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/babushka/meta_dep.rb', line 14 def self.for supplied_name, source, opts, &block name = supplied_name.to_s.downcase if name.empty? raise ArgumentError, "You can't define a template with a blank name." elsif INVALID_NAMES.include? name raise ArgumentError, "You can't use '#{name}' for a template name, because it's reserved." elsif name[VALID_NAME_START].nil? raise ArgumentError, "You can't use '#{name}' for a template name - it must start with a letter." elsif name[VALID_NAME].nil? raise ArgumentError, "You can't use '#{name}' for a template name - it can only contain [a-z0-9_]." elsif Base.sources.current_load_source.templates.for(name) raise ArgumentError, "A template called '#{name}' has already been defined." else new name, source, opts, &block end end |
Instance Method Details
- (Object) build_context(block)
56 57 58 59 60 61 62 63 |
# File 'lib/babushka/meta_dep.rb', line 56 def build_context block Class.new(MetaDepContext, &block).tap {|context| shadow = self context..send :define_method, :source_template do shadow end } end |
- (Object) contextual_name
Returns this template's name, including the source name as a prefix if this template is in a cloneable source.
A cloneable source is one that babushka knows how to automatically update; i.e. a source that babushka could have installed itself.
In effect, a cloneable source is one whose deps you prefix when you run them, so this method returns the template's name in the same form as you would refer to it when using it from another source.
52 53 54 |
# File 'lib/babushka/meta_dep.rb', line 52 def contextual_name source.cloneable? ? "#{source.name}:#{name}" : name end |
- (Object) desc
34 |
# File 'lib/babushka/meta_dep.rb', line 34 def desc; context_class.desc end |