Class: Aspera::Cli::Plugin
- Inherits:
-
Object
- Object
- Aspera::Cli::Plugin
- Defined in:
- lib/aspera/cli/plugin.rb
Overview
base class for plugins modules
Direct Known Subclasses
BasicAuthPlugin, Aspera::Cli::Plugins::Ats, Aspera::Cli::Plugins::Config, Aspera::Cli::Plugins::Cos, Aspera::Cli::Plugins::Sync
Constant Summary collapse
- GLOBAL_OPS =
[:create,:list]
- INSTANCE_OPS =
[:modify,:delete,:show]
- ALL_OPS =
[GLOBAL_OPS,INSTANCE_OPS].flatten
- @@done =
private_constant :GLOBAL_OPS,:INSTANCE_OPS,:ALL_OPS
false
Instance Method Summary collapse
- #config ⇒ Object
-
#entity_action(rest_api, res_class_path, display_fields, id_symb, id_default = nil, subkey = false) ⇒ Object
implement generic rest operations on given resource path.
- #entity_command(command, rest_api, res_class_path, display_fields, id_symb, id_default = nil, subkey = false) ⇒ Object
- #format ⇒ Object
-
#initialize(env) ⇒ Plugin
constructor
A new instance of Plugin.
- #options ⇒ Object
- #transfer ⇒ Object
Constructor Details
#initialize(env) ⇒ Plugin
Returns a new instance of Plugin.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/aspera/cli/plugin.rb', line 12 def initialize(env) @agents=env raise StandardError,"execute_action shall be redefined by subclass #{self.class}" unless respond_to?(:execute_action) raise StandardError,"ACTIONS shall be redefined by subclass" unless self.class.constants.include?(:ACTIONS) unless env[:skip_option_header] self..parser.separator "" self..parser.separator "COMMAND: #{self.class.name.split('::').last.downcase}" self..parser.separator "SUBCOMMANDS: #{self.class.const_get(:ACTIONS).map{ |p| p.to_s}.join(' ')}" self..parser.separator "OPTIONS:" end unless @@done self..add_opt_simple(:value,"extended value for create, update, list filter") self..add_opt_simple(:property,"name of property to set") self..add_opt_simple(:id,"resource identifier (#{INSTANCE_OPS.join(",")})") self.. @@done=true end end |
Instance Method Details
#config ⇒ Object
84 |
# File 'lib/aspera/cli/plugin.rb', line 84 def config;return @agents[:config];end |
#entity_action(rest_api, res_class_path, display_fields, id_symb, id_default = nil, subkey = false) ⇒ Object
implement generic rest operations on given resource path
74 75 76 77 78 |
# File 'lib/aspera/cli/plugin.rb', line 74 def entity_action(rest_api,res_class_path,display_fields,id_symb,id_default=nil,subkey=false) #res_name=res_class_path.gsub(%r{^.*/},'').gsub(%r{s$},'').gsub('_',' ') command=self..get_next_command(ALL_OPS) return entity_command(command,rest_api,res_class_path,display_fields,id_symb,id_default,subkey) end |
#entity_command(command, rest_api, res_class_path, display_fields, id_symb, id_default = nil, subkey = false) ⇒ Object
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aspera/cli/plugin.rb', line 31 def entity_command(command,rest_api,res_class_path,display_fields,id_symb,id_default=nil,subkey=false) if INSTANCE_OPS.include?(command) begin one_res_id=self..get_option(id_symb,:mandatory) rescue => e raise e if id_default.nil? one_res_id=id_default end one_res_path="#{res_class_path}/#{one_res_id}" end # parameters mandatory for create/modify if [:create,:modify].include?(command) parameters=self..get_option(:value,:mandatory) end # parameters optional for list if [:list].include?(command) parameters=self..get_option(:value,:optional) end case command when :create return {:type => :single_object, :data=>rest_api.create(res_class_path,parameters)[:data], :fields=>display_fields} when :show return {:type => :single_object, :data=>rest_api.read(one_res_path)[:data], :fields=>display_fields} when :list resp=rest_api.read(res_class_path,parameters) data=resp[:data] if resp[:http]['Content-Type'].start_with?('application/vnd.api+json') data=resp[:data][res_class_path] end data=data[res_class_path] if subkey return {:type => :object_list, :data=>data, :fields=>display_fields} when :modify property=self..get_option(:property,:optional) parameters={property => parameters} unless property.nil? rest_api.update(one_res_path,parameters) return Main.result_status('modified') when :delete rest_api.delete(one_res_path) return Main.result_status("deleted") end end |
#format ⇒ Object
86 |
# File 'lib/aspera/cli/plugin.rb', line 86 def format;return @agents[:formater];end |
#options ⇒ Object
80 |
# File 'lib/aspera/cli/plugin.rb', line 80 def ;@agents[:options];end |
#transfer ⇒ Object
82 |
# File 'lib/aspera/cli/plugin.rb', line 82 def transfer;@agents[:transfer];end |