Module: ApiScaffold::Generators::GeneratorHelpers

Included in:
ApiScaffoldGenerator
Defined in:
lib/generators/api_scaffold/generator_helpers.rb

Instance Method Summary collapse

Instance Method Details

#attributes_hashObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 44

def attributes_hash
  return {} if attributes_names.empty?

  attributes_names.map do |name|
    if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
      ["#{name}", "'secret'"]
    else
      ["#{name}", "@#{singular_table_name}.#{name}"]
    end
  end.sort.to_h
end

#attributes_stringObject



41
42
43
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 41

def attributes_string
  attributes_hash.map { |k, v| "#{k}: #{v}" }.join(", ")
end

#fixture_nameObject



33
34
35
36
37
38
39
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 33

def fixture_name
  if mountable_engine?
    (namespace_dirs + [table_name]).join("_")
  else
    table_name
  end
end

#fixture_replacementObject



29
30
31
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 29

def fixture_replacement
  Rails.application.config.generators.options[:rails][:fixture_replacement]
end

#gem_available?(gem_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 21

def gem_available?(gem_name)
  Gem::Specification::find_all_by_name(gem_name).any?
end

#prefixObject



5
6
7
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 5

def prefix
  "v#{options[:api_version]}"
end

#prefixed_class_nameObject



9
10
11
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 9

def prefixed_class_name
  "#{prefix.capitalize}::#{class_name}"
end

#prefixed_controller_class_nameObject



13
14
15
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 13

def prefixed_controller_class_name
  "#{prefix.capitalize}::#{controller_class_name}"
end

#prefixed_url(resource) ⇒ Object



17
18
19
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 17

def prefixed_url(resource)
  [prefix, resource, 'url'].join('_')
end

#test_frameworkObject



25
26
27
# File 'lib/generators/api_scaffold/generator_helpers.rb', line 25

def test_framework
  Rails.application.config.generators.options[:rails][:test_framework]
end