module BaseChip::Dsl::InstanceMethods
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/base_chip/dsl.rb, line 241 def initialize(*args) super(*args) @blks = [] @modes = [] @base_types = [] end
Public Instance Methods
absolute_path(f)
click to toggle source
# File lib/base_chip/dsl.rb, line 389 def absolute_path(f) if f =~ /^\// f else "#{BaseChip.root}/#{f}" end end
check_type(setting,value,types)
click to toggle source
# File lib/base_chip/dsl.rb, line 251 def check_type(setting,value,types) return if value.nil? if types.is_a? Array types.each do |t| return if value.is_a? t end else return if value.is_a? type end raise "setting '#{setting}' is set to #{value.inspect} which is of type '#{value.class}', but should have been set to a #{types.map{|t|"'#{t}'"}.join(' or a ')}" end
clear()
click to toggle source
# File lib/base_chip/dsl.rb, line 271 def clear self.class.possible_settings .each_key {|s| self.send s, nil } self.class.possible_child_types.each_key {|s| (hash = self.send s) and hash.delete_if {true} } @configured = false end
clone()
click to toggle source
Calls superclass method
# File lib/base_chip/dsl.rb, line 371 def clone c = super c.steal_children(self) c end
configure()
click to toggle source
# File lib/base_chip/dsl.rb, line 276 def configure return if @configured if foster ; foster.configure ; @modes += foster.modes end if parent ; parent.configure ; @modes += parent.modes end @modes.uniq! verbose "configuring #{@name}" find_parent_values(:foster) find_parent_values(:parent) @base_types.each do |t| instance_calls(t.blks) end instance_calls(@blks) @configured = true end
deep_configure()
click to toggle source
# File lib/base_chip/dsl.rb, line 262 def deep_configure configure self.class.child_types.each_key do |name| next unless hash = self.send(name.to_s.pluralize) hash.each_value do |child| child.deep_configure end end end
file(f=nil)
click to toggle source
# File lib/base_chip/dsl.rb, line 376 def file(f=nil) if f @file = absolute_path(f) if File.exist? @file instance_eval(File.read(@file),@file) else fault "file '#{@file}' could not be found for #{self.class_string.downcase} '#{@name}'" + (self.parent ? " in #{self.parent.class_string.downcase} '#{self.parent.name}'" : '') end else @file end end
find_file(file)
click to toggle source
methods that probably shouldn’t be here, common to project and block
# File lib/base_chip/dsl.rb, line 334 def find_file(file) found = nil @search_paths ||= ['', @work_dir+'/', @top_dir+'/', @project.project_root+'/'].uniq @search_paths.each do |p| return found if File.exist?(found = "#{p}#{file}") end fault "Could not resolve path to file #{file.inspect}. Attempted the following:\n#{@search_paths.map{|p| " '#{p}#{file}'"}.join("\n")}" end
find_parent_values(parent_type)
click to toggle source
# File lib/base_chip/dsl.rb, line 304 def find_parent_values(parent_type) if parent = self.send(parent_type) raise "parent #{parent.name} of type #{parent.class.class_string} has not yet been configured" unless parent.configured else return end self.class.possible_settings.each_key do |name| next unless (self.send name).nil? self.send name, (parent.send name) end self.class.possible_child_types.each do |name,type| plural = name.to_s.pluralize next unless child_defaults = parent.send(plural) hash = instance_variable_or_equal(plural,HashWithIndifferentAccess.new) child_defaults.each do |name,object| object2 = (hash[name] ||= type.new) object2.name ||= name object2.parent ||= self object2.blks = object.blks + object2.blks object2.abstract ||= object.abstract end end end
full_name()
click to toggle source
# File lib/base_chip/dsl.rb, line 342 def full_name if self == BaseChip.project nil elsif @parent and @parent.full_name "#{@parent.full_name}:#{@name}" else @name end end
Also aliased as: task_name
instance_calls(blks)
click to toggle source
# File lib/base_chip/dsl.rb, line 295 def instance_calls(blks) blks.each do |b| if b.parameters.empty? self.instance_exec(&b) else b.call(self) end end end
instance_variable_or_equal(name,value)
click to toggle source
# File lib/base_chip/dsl.rb, line 327 def instance_variable_or_equal(name,value) value = instance_variable_get("@#{name}") || value instance_variable_set "@#{name}", value value end
parent=(parent)
click to toggle source
# File lib/base_chip/dsl.rb, line 247 def parent=(parent) @parent = parent end
steal_children(object)
click to toggle source
# File lib/base_chip/dsl.rb, line 359 def steal_children(object) self.class.child_types.each_key do |name| plural = name.to_s.pluralize ohash = HashWithIndifferentAccess.new if ihash = object.send(plural) ihash.each do |key,value| ohash[key] = value.clone if value end self.send("#{plural}=", ohash) end end end
steal_settings(object)
click to toggle source
# File lib/base_chip/dsl.rb, line 352 def steal_settings(object) self.class.settings.each_key do |name| if (value = object.send(name)) self.send(name, value) end end end