Class: CfScript::Scope::Script
- Includes:
- UI
- Defined in:
- lib/cf_script/scope/script.rb
Constant Summary collapse
- VALID_OPTIONS =
[:api, :org, :username, :password, :space]
Constants included from UI
UI::COLORS, UI::EMOJI, UI::TAGS
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #apply_options ⇒ Object
- #check_options ⇒ Object
-
#initialize(options = {}) ⇒ Script
constructor
A new instance of Script.
- #run(&block) ⇒ Object
Methods included from UI
alert, call_type, debug, detail, emoji, emoji_for, error, info, print_err, print_out, progress, puts_err, puts_out, step, success, tag_char, tag_close, tag_color, tag_format, tag_open, tag_style, title, trace, ui_format, with_color_of
Methods inherited from Target
#app, #apps, #current_org, #current_space, #space, #target
Methods inherited from Base
#finalize, #method_missing, #spec_for
Methods included from Execution
Constructor Details
#initialize(options = {}) ⇒ Script
Returns a new instance of Script.
9 10 11 12 13 |
# File 'lib/cf_script/scope/script.rb', line 9 def initialize( = {}) super() @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CfScript::Scope::Base
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/cf_script/scope/script.rb', line 3 def @options end |
Instance Method Details
#apply_options ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cf_script/scope/script.rb', line 30 def # If api is given and there are no username or password, set the api if [:api] and ([:username].nil? or [:password].nil?) unless CfScript::Command.api([:api]) error :cf, "Could not set the API endpoint: #{[:api]}" raise "Could not set the API endpoint: #{[:api]}" end end # If username and password are given, call login. This also sets the api # and the space if they are given. if [:username] and [:password] unless CfScript::Command.login([:username], [:password], ) error :cf, 'Could not login with given credentials' raise 'Could not login with given credentials' end end # If a space is given, don't set it if there is a username and password, # login would have already set it. if [:space] and ([:username].nil? or [:password].nil?) # Use target, not CfScript::Command.target, so we can keep track of # the previous and current spaces and reset them on scope exit. target [:space] end end |
#check_options ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/cf_script/scope/script.rb', line 21 def .keys.each do |key| unless VALID_OPTIONS.include?(key) alert :options, "#{key} is not a valid option for the " + 'cf method. It will be ignored.' end end end |
#run(&block) ⇒ Object
15 16 17 18 19 |
# File 'lib/cf_script/scope/script.rb', line 15 def run(&block) unless .empty? exec_in(self, nil, &block) end |