class Shaf::Generator::Controller

Public Instance Methods

call() click to toggle source
# File lib/shaf/generator/controller.rb, line 10
def call
  create_controller
  create_integration_spec if options[:specs]
  add_link_to_root
end
create_controller() click to toggle source
# File lib/shaf/generator/controller.rb, line 55
def create_controller
  content = render(template, opts)
  write_output(target, content)
end
create_integration_spec() click to toggle source
# File lib/shaf/generator/controller.rb, line 60
def create_integration_spec
  content = render(spec_template, opts)
  write_output(spec_target, content)
end
model_class_name() click to toggle source
# File lib/shaf/generator/controller.rb, line 27
def model_class_name
  Utils.model_name(name)
end
name() click to toggle source
# File lib/shaf/generator/controller.rb, line 20
def name
  n = args.first || ''
  return n unless n.empty?
  raise Command::ArgumentError,
    'Please provide a controller name when using the controller generator!'
end
opts() click to toggle source
# File lib/shaf/generator/controller.rb, line 65
def opts
  {
    name: name,
    plural_name: plural_name,
    serializer_class_name: "#{model_class_name}Serializer",
    model_class_name: model_class_name,
    controller_class_name: "#{pluralized_model_name}Controller",
    policy_class_name: "#{model_class_name}Policy",
    policy_file: "policies/#{name}_policy",
    params: params
  }
end
params() click to toggle source
# File lib/shaf/generator/controller.rb, line 16
def params
  args[1..-1].map { |param| param.split(':')}
end
plural_name() click to toggle source
# File lib/shaf/generator/controller.rb, line 31
def plural_name
  Utils.pluralize(name)
end
pluralized_model_name() click to toggle source
# File lib/shaf/generator/controller.rb, line 35
def pluralized_model_name
  Utils.pluralize(model_class_name)
end
spec_target() click to toggle source
# File lib/shaf/generator/controller.rb, line 51
def spec_target
  "spec/integration/#{plural_name}_controller_spec.rb"
end
spec_template() click to toggle source
# File lib/shaf/generator/controller.rb, line 43
def spec_template
  'spec/integration_spec.rb'
end
target() click to toggle source
# File lib/shaf/generator/controller.rb, line 47
def target
  "api/controllers/#{plural_name}_controller.rb"
end
template() click to toggle source
# File lib/shaf/generator/controller.rb, line 39
def template
  'api/controller.rb'
end