Class: Roda::Project::MainContext

Inherits:
Object
  • Object
show all
Includes:
Helpers::Ids
Defined in:
lib/roda/project/main_context.rb

Defined Under Namespace

Classes: InvalidValue

Constant Summary collapse

VALID_PROJECT_NAME_REGEX =
/^[a-zA-Z][a-zA-Z0-9_]*$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Ids

#api_id, #fullstack_id, #id_to_string, #minimal_id, #minitest_id, #mysql_id, #postgresql_id, #rspec_id, #sqlite_id

Instance Attribute Details

#baseObject

Returns the value of attribute base.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def base
  @base
end

#databaseObject

Returns the value of attribute database.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def database
  @database
end

#database_typeObject

Returns the value of attribute database_type.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def database_type
  @database_type
end

#db_gemObject (readonly)

Returns the value of attribute db_gem.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def db_gem
  @db_gem
end

#default_db_urlObject (readonly)

Returns the value of attribute default_db_url.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def default_db_url
  @default_db_url
end

#project_nameObject

Returns the value of attribute project_name.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def project_name
  @project_name
end

#rodauthObject

Returns the value of attribute rodauth.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def rodauth
  @rodauth
end

#testsObject

Returns the value of attribute tests.



10
11
12
# File 'lib/roda/project/main_context.rb', line 10

def tests
  @tests
end

Instance Method Details

#api?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/roda/project/main_context.rb', line 119

def api?
  base == api_id
end

#const_project_nameObject



153
154
155
# File 'lib/roda/project/main_context.rb', line 153

def const_project_name
  @const_project_name ||= project_name.split("_").map(&:capitalize).join
end

#database?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/roda/project/main_context.rb', line 131

def database?
  database == true
end

#foo_bar_exampleObject

rubocop:disable Lint/InterpolationCheck



102
103
104
105
106
# File 'lib/roda/project/main_context.rb', line 102

def foo_bar_example
  return 'view("bar")' if fullstack?

  '{ foo: "bar" }'
end

#fullstack?Boolean

rubocop:enable Lint/InterpolationCheck

Returns:

  • (Boolean)


115
116
117
# File 'lib/roda/project/main_context.rb', line 115

def fullstack?
  base == fullstack_id
end

#minimal?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/roda/project/main_context.rb', line 123

def minimal?
  base == minimal_id
end

#minitest?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/roda/project/main_context.rb', line 97

def minitest?
  tests == minitest_id
end

#mysql?Boolean

Returns:

  • (Boolean)


135
136
137
138
139
# File 'lib/roda/project/main_context.rb', line 135

def mysql?
  return false unless database?

  database_type == mysql_id
end

#postgresql?Boolean

Returns:

  • (Boolean)


141
142
143
144
145
# File 'lib/roda/project/main_context.rb', line 141

def postgresql?
  return false unless database?

  database_type == postgresql_id
end

#rodauth?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/roda/project/main_context.rb', line 127

def rodauth?
  rodauth == true
end

#root_exampleObject



108
109
110
111
112
# File 'lib/roda/project/main_context.rb', line 108

def root_example
  return 'view("index")' if fullstack?

  '{ message: "#{t.hello.message}" }'
end

#rspec?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/roda/project/main_context.rb', line 93

def rspec?
  tests == rspec_id
end

#sqlite?Boolean

Returns:

  • (Boolean)


147
148
149
150
151
# File 'lib/roda/project/main_context.rb', line 147

def sqlite?
  return false unless database?

  database_type == sqlite_id
end

#to_thor_optionObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/roda/project/main_context.rb', line 21

def to_thor_option
  option = <<~RUBY
  option :main_context, type: :hash, default: {
project_name: "#{project_name}",
base: #{id_to_string(base, :base)},
rodauth: #{rodauth},
tests: #{id_to_string(tests, :tests)},
database: #{database},
  RUBY
  if database?
    option << "    database_type: #{id_to_string(database_type, :database)},"
  end
  option << "\n    }"
end