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.
10 11 12 |
# File 'lib/roda/project/main_context.rb', line 10 def base @base end |
#database ⇒ Object
Returns the value of attribute database.
10 11 12 |
# File 'lib/roda/project/main_context.rb', line 10 def database @database end |
#database_type ⇒ Object
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_gem ⇒ Object (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_url ⇒ Object (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_name ⇒ Object
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 |
#rodauth ⇒ Object
Returns the value of attribute rodauth.
10 11 12 |
# File 'lib/roda/project/main_context.rb', line 10 def rodauth @rodauth end |
#tests ⇒ Object
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
119 120 121 |
# File 'lib/roda/project/main_context.rb', line 119 def api? base == api_id end |
#const_project_name ⇒ Object
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
131 132 133 |
# File 'lib/roda/project/main_context.rb', line 131 def database? database == true end |
#foo_bar_example ⇒ Object
rubocop:disable Lint/InterpolationCheck
102 103 104 105 106 |
# File 'lib/roda/project/main_context.rb', line 102 def return 'view("bar")' if fullstack? '{ foo: "bar" }' end |
#fullstack? ⇒ Boolean
rubocop:enable Lint/InterpolationCheck
115 116 117 |
# File 'lib/roda/project/main_context.rb', line 115 def fullstack? base == fullstack_id end |
#minimal? ⇒ Boolean
123 124 125 |
# File 'lib/roda/project/main_context.rb', line 123 def minimal? base == minimal_id end |
#minitest? ⇒ Boolean
97 98 99 |
# File 'lib/roda/project/main_context.rb', line 97 def minitest? tests == minitest_id end |
#mysql? ⇒ 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
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
127 128 129 |
# File 'lib/roda/project/main_context.rb', line 127 def rodauth? rodauth == true end |
#root_example ⇒ Object
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
93 94 95 |
# File 'lib/roda/project/main_context.rb', line 93 def rspec? tests == rspec_id end |
#sqlite? ⇒ 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_option ⇒ Object
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 |