Module: Theme::Command::Common::RootHelper

Included in:
Pull, Push, Serve, Share
Defined in:
lib/project_types/theme/commands/common/root_helper.rb

Instance Method Summary collapse

Instance Method Details

#exist_and_not_empty?(root) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/project_types/theme/commands/common/root_helper.rb', line 45

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

#root_value(options, name) ⇒ Object



9
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
# File 'lib/project_types/theme/commands/common/root_helper.rb', line 9

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)


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

def valid_theme_directory?(root)
  Theme::Models::SpecificationHandlers::Theme.new(root).valid? ||
    current_directory_confirmed?
end