Class: Babushka::DepDefiner

Direct Known Subclasses

DepContext

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns a new instance of DepDefiner



25
26
27
28
29
30
31
# File 'lib/babushka/dep_definer.rb', line 25

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



36
37
38
39
40
41
42
43
44
45
# File 'lib/babushka/dep_definer.rb', line 36

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

Returns:

  • (Boolean)


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

def failed?; @failed end

#get_source_location_for(blk) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/babushka/dep_definer.rb', line 64

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



47
48
49
50
# File 'lib/babushka/dep_definer.rb', line 47

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

Returns:

  • (Boolean)


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

def loaded?; @loaded end

#nameObject



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

def name; dependency.name end

#source_locationObject



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

def source_location
  get_source_location_for(block)
end

#source_location_for(block_name) ⇒ Object



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

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

#unmeetable!(message) ⇒ Object



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

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