Class: Babushka::Renderable
- Includes:
- RunHelpers, ShellHelpers
- Defined in:
- lib/babushka/renderable.rb
Constant Summary collapse
- SEAL_REGEXP =
/# Generated by babushka-[\d\.]+ at [a-zA-Z\d\-\:\s+]+, from [0-9a-f]{40}+\. [0-9a-f]{40}/
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #clean? ⇒ Boolean
- #exists? ⇒ Boolean
- #from?(source) ⇒ Boolean
-
#initialize(path) ⇒ Renderable
constructor
A new instance of Renderable.
- #render(source, opts = {}) ⇒ Object
- #source_sha ⇒ Object
Methods included from RunHelpers
#_by_babushka, #added_by_babushka, #append_to_file, #babushka_config?, #bundle_rake, #change_line, #change_with_sed, #check_file, #edited_by_babushka, #erb_path_for, #grep, #hostname, #insert_into_file, #log_and_open, #mysql, #rake, #yaml
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!
Constructor Details
#initialize(path) ⇒ Renderable
Returns a new instance of Renderable.
9 10 11 |
# File 'lib/babushka/renderable.rb', line 9 def initialize path @path = path.p end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/babushka/renderable.rb', line 8 def path @path end |
Instance Method Details
#clean? ⇒ Boolean
28 29 30 |
# File 'lib/babushka/renderable.rb', line 28 def clean? Inkan.legitimate? path end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/babushka/renderable.rb', line 24 def exists? path.exists? end |
#from?(source) ⇒ Boolean
32 33 34 |
# File 'lib/babushka/renderable.rb', line 32 def from? source exists? && source_sha == sha_of(source) end |
#render(source, opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/babushka/renderable.rb', line 13 def render source, opts = {} shell("cat > '#{path}'", :input => inkan_output_for(source, opts), :sudo => opts[:sudo] ).tap {|result| if result sudo "chmod #{opts[:perms]} '#{path}'" if opts[:perms] end } end |
#source_sha ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/babushka/renderable.rb', line 36 def source_sha path.open {|f| [f.gets, f.gets].compact.detect {|l| l[/^#!/].nil? # The first line that isn't a hashbang } || '' }.scan(/, from ([0-9a-f]{40})\./).flatten.first end |