Class: Babushka::DepDefiner

Direct Known Subclasses

DepContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Vars::Helpers

define_var, merge, print_var_removal_for, set, var

Methods included from VersionOf::Helpers

VersionOf

Methods included from RunHelpers

_by_babushka, added_by_babushka, append_to_file, babushka_config?, edited_by_babushka, erb_path_for, render_erb

Methods included from PathHelpers

cd, in_build_dir, in_download_dir

Methods included from ShellHelpers

cmd_dir, current_username, log_shell, login_shell, raw_shell, shell, shell!, shell?, shell_cmd, sudo, which

Methods included from LogHelpers

debug, deprecated!, log, log_block, log_error, log_ok, log_stderr, log_warn, removed!

Methods included from AcceptsBlockFor

#block_for, #default_block_for, #default_blocks, #has_block?, included, #specific_block_for, #store_block_for

Methods included from AcceptsValueFor

included, #store_value_for, #value_for

Methods included from AcceptsListFor

included, #list_for, #store_list_for

Constructor Details

#initialize(dep, &block) ⇒ DepDefiner



28
29
30
31
32
33
34
# File 'lib/babushka/dep_definer.rb', line 28

def initialize dep, &block
  @dependency = dep
  @payload = {}
  @block = block
  @loaded, @failed = false, false
  @current_platform = nil
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block



19
20
21
# File 'lib/babushka/dep_definer.rb', line 19

def block
  @block
end

#dependencyObject (readonly)

Returns the value of attribute dependency



19
20
21
# File 'lib/babushka/dep_definer.rb', line 19

def dependency
  @dependency
end

#payloadObject (readonly)

Returns the value of attribute payload



19
20
21
# File 'lib/babushka/dep_definer.rb', line 19

def payload
  @payload
end

Instance Method Details

#basenameObject



22
# File 'lib/babushka/dep_definer.rb', line 22

def basename; dependency.basename end

#define!Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/babushka/dep_definer.rb', line 39

def define!
  unless loaded? || failed?
    define_elements!
    @loaded, @failed = true, false
  end
  self
rescue StandardError => e
  @loaded, @failed = false, true
  raise e
end

#failed?Boolean



37
# File 'lib/babushka/dep_definer.rb', line 37

def failed?; @failed end

#get_source_location_for(blk) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/babushka/dep_definer.rb', line 67

def get_source_location_for blk
  if blk.respond_to?(:source_location) # Not present on cruby-1.8.
    blk.source_location
  else
    blk.inspect.scan(/\#\<Proc\:0x[0-9a-f]+\@([^:]+):(\d+)>/).flatten
  end
end

#invoke(block_name) ⇒ Object



50
51
52
53
# File 'lib/babushka/dep_definer.rb', line 50

def invoke block_name
  define! unless loaded?
  instance_eval(&send(block_name)) unless failed?
end

#load_pathObject



23
# File 'lib/babushka/dep_definer.rb', line 23

def load_path; dependency.load_path end

#loaded?Boolean



36
# File 'lib/babushka/dep_definer.rb', line 36

def loaded?; @loaded end

#nameObject



21
# File 'lib/babushka/dep_definer.rb', line 21

def name; dependency.name end

#source_locationObject



59
60
61
# File 'lib/babushka/dep_definer.rb', line 59

def source_location
  get_source_location_for(block)
end

#source_location_for(block_name) ⇒ Object



63
64
65
# File 'lib/babushka/dep_definer.rb', line 63

def source_location_for block_name
  get_source_location_for send(block_name) if has_block? block_name
end

#unmeetable!(message) ⇒ Object



55
56
57
# File 'lib/babushka/dep_definer.rb', line 55

def unmeetable! message
  raise Babushka::UnmeetableDep, message
end