Module: Shef::Extensions::Object
- Included in:
- Object
- Defined in:
- lib/chef/shef/ext.rb
Overview
Extensions to be included in object. These are methods that have to be defined on object but are not part of the user interface. Methods that are part of the user interface should have help text defined with the desc
macro, and need to be defined directly on Object in ext.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #ensure_session_select_defined ⇒ Object
- #find_or_create_session_for(context_obj) ⇒ Object
- #help_banner(title = nil) ⇒ Object
-
#off ⇒ Object
returns
:off
so you can just do ‘tracing off’. -
#on ⇒ Object
helpfully returns
:on
so we can have sugary syntax like ‘tracing on’.
Instance Method Details
#ensure_session_select_defined ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chef/shef/ext.rb', line 27 def ensure_session_select_defined # irb breaks if you prematurely define IRB::JobMangager # so these methods need to be defined at the latest possible time. unless jobs.respond_to?(:select_session_by_context) def jobs.select_session_by_context(&block) @jobs.select { |job| block.call(job[1].context.main)} end end unless jobs.respond_to?(:session_select) def jobs.select_shef_session(target_context) session = if target_context.kind_of?(Class) select_session_by_context { |main| main.kind_of?(target_context) } else select_session_by_context { |main| main.equal?(target_context) } end Array(session.first)[1] end end end |
#find_or_create_session_for(context_obj) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/chef/shef/ext.rb', line 48 def find_or_create_session_for(context_obj) ensure_session_select_defined if subsession = jobs.select_shef_session(context_obj) jobs.switch(subsession) else irb(context_obj) end end |
#help_banner(title = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chef/shef/ext.rb', line 57 def (title=nil) = [] << "" << title if title << "".ljust(80, "=") << "| " + "Command".ljust(25) + "| " + "Description" << "".ljust(80, "=") self.class.all_help_descriptions.each do |cmd, description| << "| " + cmd.ljust(25) + "| " + description end << "".ljust(80, "=") << "\n" .join("\n") end |
#off ⇒ Object
returns :off
so you can just do ‘tracing off’
78 79 80 |
# File 'lib/chef/shef/ext.rb', line 78 def off :off end |
#on ⇒ Object
helpfully returns :on
so we can have sugary syntax like ‘tracing on’
73 74 75 |
# File 'lib/chef/shef/ext.rb', line 73 def on :on end |