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.



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

def base
  @base
end

#databaseObject

Returns the value of attribute database.



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

def database
  @database
end

#database_typeObject

Returns the value of attribute database_type.



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

def database_type
  @database_type
end

#db_gemObject (readonly)

Returns the value of attribute db_gem.



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

def db_gem
  @db_gem
end

#default_db_urlObject (readonly)

Returns the value of attribute default_db_url.



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

def default_db_url
  @default_db_url
end

#project_nameObject

Returns the value of attribute project_name.



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

def project_name
  @project_name
end

#rodauthObject

Returns the value of attribute rodauth.



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

def rodauth
  @rodauth
end

#testsObject

Returns the value of attribute tests.



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

def tests
  @tests
end

Instance Method Details

#api?Boolean

Returns:

  • (Boolean)


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

def api?
  base == api_id
end

#const_project_nameObject



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

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

#database?Boolean

Returns:

  • (Boolean)


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

def database?
  database == true
end

#foo_bar_exampleObject

rubocop:disable Lint/InterpolationCheck



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

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

  '{ foo: "bar" }'
end

#fullstack?Boolean

rubocop:enable Lint/InterpolationCheck

Returns:

  • (Boolean)


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

def fullstack?
  base == fullstack_id
end

#minimal?Boolean

Returns:

  • (Boolean)


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

def minimal?
  base == minimal_id
end

#minitest?Boolean

Returns:

  • (Boolean)


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

def minitest?
  tests == minitest_id
end

#mysql?Boolean

Returns:

  • (Boolean)


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

def mysql?
  return false unless database?

  database_type == mysql_id
end

#postgresql?Boolean

Returns:

  • (Boolean)


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

def postgresql?
  return false unless database?

  database_type == postgresql_id
end

#rodauth?Boolean

Returns:

  • (Boolean)


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

def rodauth?
  rodauth == true
end

#root_exampleObject



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

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

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

#rspec?Boolean

Returns:

  • (Boolean)


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

def rspec?
  tests == rspec_id
end

#sqlite?Boolean

Returns:

  • (Boolean)


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

def sqlite?
  return false unless database?

  database_type == sqlite_id
end

#to_thor_optionObject



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

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