Module: Utils::LitaPuppet::Text
- Included in:
- Lita::Handlers::Puppet
- Defined in:
- lib/utils/lita_puppet/text.rb
Overview
Utility methods for manipulating text
Instance Method Summary collapse
- #agent_command ⇒ Object
-
#as_code(text) ⇒ Object
Format some text as code Note that this is HipChat specific for the moment TODO: Make this not HipChat specific.
-
#class_camel(text) ⇒ Object
camel case puppet classes.
- #r10k_command(environment, mod) ⇒ Object
-
#sanitze_for_chat(text) ⇒ Object
Strip off bad characters.
Instance Method Details
#agent_command ⇒ Object
5 6 7 8 9 10 |
# File 'lib/utils/lita_puppet/text.rb', line 5 def agent_command command = 'puppet agent' command << ' --onetime --verbose --no-daemonize' command << ' --no-usecacheonfailure' command << ' --no-splay --show_diff 2>&1' end |
#as_code(text) ⇒ Object
Format some text as code
Note that this is HipChat specific for the moment
TODO: Make this not HipChat specific
15 16 17 |
# File 'lib/utils/lita_puppet/text.rb', line 15 def as_code(text) '/code ' + sanitze_for_chat(text) end |
#class_camel(text) ⇒ Object
camel case puppet classes
20 21 22 |
# File 'lib/utils/lita_puppet/text.rb', line 20 def class_camel(text) text.split('::').map(&:capitalize).join('::') end |
#r10k_command(environment, mod) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/utils/lita_puppet/text.rb', line 24 def r10k_command(environment, mod) command = 'r10k deploy' if environment && mod command << " module -e #{environment} #{mod} -v" else command << ' environment' command << " #{environment}" if environment command << ' -pv' end end |
#sanitze_for_chat(text) ⇒ Object
Strip off bad characters
36 37 38 39 40 41 42 43 |
# File 'lib/utils/lita_puppet/text.rb', line 36 def sanitze_for_chat(text) # Remove bash colorings o = text.gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]/, '') # Limit text to 50 lines o = (o.lines.to_a[0...49] << "\n... truncated to 50 lines").join if o.lines.size > 50 # return the output o end |