Class: KCommercial::KCPipeline::Command::ResourceGenerator

Inherits:
KCommercial::KCPipeline::Command show all
Defined in:
lib/KCommercialPipeline/command/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ ResourceGenerator

Returns a new instance of ResourceGenerator.



22
23
24
25
26
27
# File 'lib/KCommercialPipeline/command/resource.rb', line 22

def initialize(argv)
  @name = argv.shift_argument
  @super_module = argv.option('super-module', :MKResources)
  @language = argv.option('language', nil)
  super argv
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



9
10
11
# File 'lib/KCommercialPipeline/command/resource.rb', line 9

def language
  @language
end

#super_moduleObject

Returns the value of attribute super_module.



10
11
12
# File 'lib/KCommercialPipeline/command/resource.rb', line 10

def super_module
  @super_module
end

Class Method Details

.optionsObject



14
15
16
17
18
19
20
# File 'lib/KCommercialPipeline/command/resource.rb', line 14

def self.options
  [
    ['--super-module=SUPER', 'The super module for the resources class. default is MKResources'],
    ['--language=language', "The generated language for the code, default is swift. we support "\
                            "#{CocoaDepot::Resources::Generator::SupportLanguage.values}"]
  ].concat(super)
end

Instance Method Details

#runObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/KCommercialPipeline/command/resource.rb', line 38

def run
  options = {
    :super_module => @super_module,
    :language => @language
  }
  # 星云url
  source_url = 'https://ad-star.corp.kuaishou.com/res/sdk_space/zip?space=8'
  source = KCommercial::Resources::SourceManager.shared.source_with_url(source_url)
  generator = KCommercial::Resources::Generator.new(@component, source, options)
  generator.generate!
end

#validate!Object



29
30
31
32
33
34
35
36
# File 'lib/KCommercialPipeline/command/resource.rb', line 29

def validate!
  super
  help! 'A name for the Pod is required.' unless @name
   @depot = CocoaDepot::Depot.instance
   help! 'You must in any depot' unless @depot
   @component = @depot.materials_cache.component_for_name @name
   help! "There is no component named #{@name}" unless @component
end