Class: GoNative::Plugins::IOS::Create

Inherits:
Object
  • Object
show all
Extended by:
DSL::Serviceable
Defined in:
lib/gonative/plugins/ios/create.rb

Constant Summary collapse

TEMPLATE_DIRECTORY_PATH =
File.expand_path(File.join(__dir__, '../../../..', 'templates', 'plugins', 'ios'))
COMMON_TEMPLATES_PATH =
File.join(TEMPLATE_DIRECTORY_PATH, 'common')
LANGUAGES =
%w[objc swift].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin_name, language) ⇒ Create

Returns a new instance of Create.



20
21
22
23
# File 'lib/gonative/plugins/ios/create.rb', line 20

def initialize(plugin_name, language)
  @plugin_name = plugin_name
  @language = language
end

Instance Attribute Details

#languageObject (readonly)

Returns the value of attribute language.



18
19
20
# File 'lib/gonative/plugins/ios/create.rb', line 18

def language
  @language
end

#plugin_nameObject (readonly)

Returns the value of attribute plugin_name.



18
19
20
# File 'lib/gonative/plugins/ios/create.rb', line 18

def plugin_name
  @plugin_name
end

Instance Method Details

#assert_not_exists!Object

Raises:



32
33
34
35
36
# File 'lib/gonative/plugins/ios/create.rb', line 32

def assert_not_exists!
  return unless File.directory?(plugin_name)

  raise Error, "Directory #{plugin_name} already exists"
end

#callObject



25
26
27
28
29
30
# File 'lib/gonative/plugins/ios/create.rb', line 25

def call
  assert_not_exists!
  set_working_dir!
  cp_template_files!
  Utils::TemplateInflator.new(plugin_name: plugin_name, repo_name: repo_name).call
end

#cp_template_files!Object



43
44
45
46
# File 'lib/gonative/plugins/ios/create.rb', line 43

def cp_template_files!
  FileUtils.cp_r("#{COMMON_TEMPLATES_PATH}/.", '.')
  system('ditto', File.join(TEMPLATE_DIRECTORY_PATH, 'language-specific', language), '.')
end

#repo_nameObject



48
49
50
# File 'lib/gonative/plugins/ios/create.rb', line 48

def repo_name
  plugin_name.underscore.dasherize.prepend 'ios-'
end

#set_working_dir!Object



38
39
40
41
# File 'lib/gonative/plugins/ios/create.rb', line 38

def set_working_dir!
  FileUtils.mkdir(plugin_name)
  FileUtils.cd(plugin_name)
end