Class: Roda::Project::MainContext
- Inherits:
-
Object
- Object
- Roda::Project::MainContext
- 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
-
#base ⇒ Object
Returns the value of attribute base.
-
#database ⇒ Object
Returns the value of attribute database.
-
#database_type ⇒ Object
Returns the value of attribute database_type.
-
#db_gem ⇒ Object
readonly
Returns the value of attribute db_gem.
-
#default_db_url ⇒ Object
readonly
Returns the value of attribute default_db_url.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#rodauth ⇒ Object
Returns the value of attribute rodauth.
-
#tests ⇒ Object
Returns the value of attribute tests.
Instance Method Summary collapse
- #api? ⇒ Boolean
- #const_project_name ⇒ Object
- #database? ⇒ Boolean
-
#foo_bar_example ⇒ Object
rubocop:disable Lint/InterpolationCheck.
-
#fullstack? ⇒ Boolean
rubocop:enable Lint/InterpolationCheck.
- #minimal? ⇒ Boolean
- #minitest? ⇒ Boolean
- #mysql? ⇒ Boolean
- #postgresql? ⇒ Boolean
- #rodauth? ⇒ Boolean
- #root_example ⇒ Object
- #rspec? ⇒ Boolean
- #sqlite? ⇒ Boolean
- #to_thor_option ⇒ Object
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
#base ⇒ Object
Returns the value of attribute base.
9 10 11 |
# File 'lib/roda/project/main_context.rb', line 9 def base @base end |
#database ⇒ Object
Returns the value of attribute database.
9 10 11 |
# File 'lib/roda/project/main_context.rb', line 9 def database @database end |
#database_type ⇒ Object
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_gem ⇒ Object (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_url ⇒ Object (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_name ⇒ Object
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 |
#rodauth ⇒ Object
Returns the value of attribute rodauth.
9 10 11 |
# File 'lib/roda/project/main_context.rb', line 9 def rodauth @rodauth end |
#tests ⇒ Object
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
118 119 120 |
# File 'lib/roda/project/main_context.rb', line 118 def api? base == api_id end |
#const_project_name ⇒ Object
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
130 131 132 |
# File 'lib/roda/project/main_context.rb', line 130 def database? database == true end |
#foo_bar_example ⇒ Object
rubocop:disable Lint/InterpolationCheck
101 102 103 104 105 |
# File 'lib/roda/project/main_context.rb', line 101 def return 'view("bar")' if fullstack? '{ foo: "bar" }' end |
#fullstack? ⇒ Boolean
rubocop:enable Lint/InterpolationCheck
114 115 116 |
# File 'lib/roda/project/main_context.rb', line 114 def fullstack? base == fullstack_id end |
#minimal? ⇒ Boolean
122 123 124 |
# File 'lib/roda/project/main_context.rb', line 122 def minimal? base == minimal_id end |
#minitest? ⇒ Boolean
96 97 98 |
# File 'lib/roda/project/main_context.rb', line 96 def minitest? tests == minitest_id end |
#mysql? ⇒ 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
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
126 127 128 |
# File 'lib/roda/project/main_context.rb', line 126 def rodauth? rodauth == true end |
#root_example ⇒ Object
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
92 93 94 |
# File 'lib/roda/project/main_context.rb', line 92 def rspec? tests == rspec_id end |
#sqlite? ⇒ 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_option ⇒ Object
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 |