Class: HanamiId::Generate::Auth

Inherits:
Hanami::CLI::Commands::Command
  • Object
show all
Defined in:
lib/hanami_id-generators/generate/auth.rb

Constant Summary collapse

CONTROLLER_ACTIONS =
{
  "sessions"      => {
    "new"    => "GET",
    "create" => "POST",
    "delete" => "DELETE"
  },
  "registrations" => {
    "index"  => "GET",
    "new"    => "GET",
    "create" => "POST",
    "edit"   => "GET",
    "show"   => "GET",
    "update" => "PUT",
    "delete" => "DELETE"
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Auth

Returns a new instance of Auth.



49
50
51
52
# File 'lib/hanami_id-generators/generate/auth.rb', line 49

def initialize(*args)
  super
  @auth_templates = HanamiId::Generators.templates
end

Instance Attribute Details

#auth_templatesObject

Returns the value of attribute auth_templates.



46
47
48
# File 'lib/hanami_id-generators/generate/auth.rb', line 46

def auth_templates
  @auth_templates
end

#contextObject

Returns the value of attribute context.



47
48
49
# File 'lib/hanami_id-generators/generate/auth.rb', line 47

def context
  @context
end

Instance Method Details

#call(app:, model:, modules:, login_column:, password_column:, id_type:, mode:, **options) ⇒ Object

rubocop:disable Metrics/AbcSize



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hanami_id-generators/generate/auth.rb', line 55

def call(
  app:, model:, modules:, login_column:, password_column:, id_type:,
  mode:, **options
)
  HanamiId.logger.info "Generating #{app} app!"
  HanamiId.model_name = model
  @context = Hanami::CLI::Commands::Context.new(
    app: app,
    model: HanamiId.model_name,
    repository: HanamiId.repository_name,
    modules: modules,
    id_type: id_type,
    login_column: ,
    password_column: password_column,
    options: options.merge(project: app)
  )

  generate_default_app
  generate_default_entity
  generate_default_repository
  generate_default_migration
  generate_default_actions(modules)
  generate_default_routes
  add_initializer(mode)
  add_config if mode == "project"
  inject_authentication_require
  inject_warden_helper
end