Module: FluidCLI::Commands::Theme::Common::RootHelper

Included in:
Dev, Pull, Push
Defined in:
lib/fluid_cli/commands/theme/common/root_helper.rb

Constant Summary collapse

REQUIRED_FOLDERS =
%w(config layouts sections product shop_page).freeze

Instance Method Summary collapse

Instance Method Details

#exist_and_not_empty?(root) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fluid_cli/commands/theme/common/root_helper.rb', line 46

def exist_and_not_empty?(root)
  Dir.exist?(root) && !Dir[File.join(root, "*")].empty?
end

#root_value(options, name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fluid_cli/commands/theme/common/root_helper.rb', line 10

def root_value(options, name)
  argv = default_argv(options)
  command_index = argv.index(name.to_s)

  return "." if command_index.nil?

  next_index = command_index + 1
  option_by_key = options_map(options)

  while next_index < argv.size
    element = argv[next_index]
    key, value = key_value_tuple(element)
    option = option_by_key[key]

    return element if option.nil?

    # Skip the option argument
    next_index += 1 if !option.arg.nil? && !value

    # PATTERN arguments take precedence over the `root`
    if option.arg =~ /PATTERN/ && !value
      next_index += 1 while option_argument?(argv, next_index, option_by_key)
      next
    end

    next_index += 1
  end

  "."
end

#valid_theme_directory?(root) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/fluid_cli/commands/theme/common/root_helper.rb', line 41

def valid_theme_directory?(root)
  REQUIRED_FOLDERS.all? { |required_folder| Dir.exist?(File.join(root, required_folder)) } ||
    current_directory_confirmed?
end