Class: Roda::Project::Context

Inherits:
Object
  • Object
show all
Includes:
Helpers::Ids
Defined in:
lib/roda/project/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, #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/context.rb', line 9

def base
  @base
end

#databaseObject

Returns the value of attribute database.



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

def database
  @database
end

#database_typeObject

Returns the value of attribute database_type.



9
10
11
# File 'lib/roda/project/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/context.rb', line 9

def db_gem
  @db_gem
end

#dev_db_urlObject (readonly)

Returns the value of attribute dev_db_url.



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

def dev_db_url
  @dev_db_url
end

#project_nameObject

Returns the value of attribute project_name.



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

def project_name
  @project_name
end

#rodauthObject

Returns the value of attribute rodauth.



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

def rodauth
  @rodauth
end

#testsObject

Returns the value of attribute tests.



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

def tests
  @tests
end

Instance Method Details

#api?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/roda/project/context.rb', line 101

def api?
  base == api_id
end

#const_project_nameObject



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

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

#database?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/roda/project/context.rb', line 109

def database?
  database == true
end

#foo_bar_exampleObject

rubocop:disable Lint/InterpolationCheck



84
85
86
87
88
# File 'lib/roda/project/context.rb', line 84

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

  '{ foo: "bar" }'
end

#fullstack?Boolean

rubocop:enable Lint/InterpolationCheck

Returns:

  • (Boolean)


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

def fullstack?
  base == fullstack_id
end

#minitest?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/roda/project/context.rb', line 79

def minitest?
  tests == minitest_id
end

#mysql?Boolean

Returns:

  • (Boolean)


113
114
115
116
117
# File 'lib/roda/project/context.rb', line 113

def mysql?
  return false unless database?

  database_type == mysql_id
end

#postgresql?Boolean

Returns:

  • (Boolean)


119
120
121
122
123
# File 'lib/roda/project/context.rb', line 119

def postgresql?
  return false unless database?

  database_type == postgresql_id
end

#rodauth?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/roda/project/context.rb', line 105

def rodauth?
  rodauth == true
end

#root_exampleObject



90
91
92
93
94
# File 'lib/roda/project/context.rb', line 90

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

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

#rspec?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/roda/project/context.rb', line 75

def rspec?
  tests == rspec_id
end

#sqlite?Boolean

Returns:

  • (Boolean)


125
126
127
128
129
# File 'lib/roda/project/context.rb', line 125

def sqlite?
  return false unless database?

  database_type == sqlite_id
end