Module: Fresco

Defined in:
lib/fresco/cli.rb,
lib/fresco.rb,
lib/fresco/paths.rb,
lib/fresco/cli/dev.rb,
lib/fresco/cli/new.rb,
lib/fresco/version.rb,
lib/fresco/cli/build.rb,
lib/fresco/cli/release.rb,
lib/fresco/model_builder.rb,
lib/fresco/schema_builder.rb,
lib/fresco/database_config.rb,
lib/fresco/runtime/runtime.rb,
lib/fresco/runtime/welcome.rb,
lib/fresco/migration_builder.rb,
lib/fresco/runtime/db_sqlite.rb,
lib/fresco/runtime/db_postgres.rb

Overview

Build-time migration DSL. db/migrations/<NNNN>_<name>.rb files each call ‘Fresco.migration “<NNNN>_<name>” do … end`. `fresco build` loads all migration files in sorted order and emits the captured SQL into generated/migrations.rb, which the runtime runs via `./app db:migrate` / `./app db:rollback`.

Each migration captures two ordered Arrays of SQL strings (up and down). No DSL helpers for ALTER / ADD / RENAME yet — write raw SQL in the block. Adapter-specific syntax goes in the file the developer wrote; we don’t translate. (M6+ could add adapter-aware helpers, but raw SQL covers the M5 footprint.)

Defined Under Namespace

Modules: Db, Paths Classes: Action, App, Application, CLI, MigrationBuilder, ModelBuilder, Router, SchemaBuilder, TableBuilder, Welcome

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.add_sql_micros!(us = 0) ⇒ Object



155
156
157
158
# File 'lib/fresco/runtime/runtime.rb', line 155

def self.add_sql_micros!(us = 0)
  @db_sql_total_micros += us
  @db_sql_count        += 1
end

.appObject



14
15
16
# File 'lib/fresco.rb', line 14

def self.app
  @app ||= Application.new
end

.class_to_path(name) ⇒ Object



35
36
37
# File 'lib/fresco.rb', line 35

def self.class_to_path(name)
  name.split("::").map { |seg| seg.gsub(/([a-z0-9])([A-Z])/, '\1_\2').downcase }.join("/")
end

.const_get_path(path) ⇒ Object



51
52
53
# File 'lib/fresco.rb', line 51

def self.const_get_path(path)
  path.split("::").inject(Object) { |mod, seg| mod.const_get(seg, false) }
end

.const_set_path(path, value) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fresco.rb', line 39

def self.const_set_path(path, value)
  parts = path.split("::")
  parent = parts[0...-1].inject(Object) do |mod, seg|
    if mod.const_defined?(seg, false)
      mod.const_get(seg, false)
    else
      mod.const_set(seg, Module.new)
    end
  end
  parent.const_set(parts.last, value) unless parent.const_defined?(parts.last, false)
end

.database(adapter, path: "", url: "") ⇒ Object



29
30
31
32
33
# File 'lib/fresco/database_config.rb', line 29

def self.database(adapter, path: "", url: "")
  @database_adapter = adapter
  @database_path    = path
  @database_url     = url
end

.database_adapterObject



17
18
19
# File 'lib/fresco/database_config.rb', line 17

def self.database_adapter
  @database_adapter
end

.database_pathObject



21
22
23
# File 'lib/fresco/database_config.rb', line 21

def self.database_path
  @database_path
end

.database_urlObject



25
26
27
# File 'lib/fresco/database_config.rb', line 25

def self.database_url
  @database_url
end

.db_sql_query_countObject



146
147
148
# File 'lib/fresco/runtime/runtime.rb', line 146

def self.db_sql_query_count
  @db_sql_count
end

.db_sql_total_microsObject



142
143
144
# File 'lib/fresco/runtime/runtime.rb', line 142

def self.db_sql_total_micros
  @db_sql_total_micros
end

.migration(name, &blk) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/fresco/migration_builder.rb', line 19

def self.migration(name, &blk)
  builder = Fresco::MigrationBuilder.new
  builder.instance_eval(&blk) if blk
  @migrations << {
    name:     name,
    up_sql:   builder.up_sql,
    down_sql: builder.down_sql,
  }
end

.migrationsObject



15
16
17
# File 'lib/fresco/migration_builder.rb', line 15

def self.migrations
  @migrations
end

.model(name, table:, &blk) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/fresco/model_builder.rb', line 15

def self.model(name, table:, &blk)
  builder = Fresco::ModelBuilder.new
  builder.instance_eval(&blk) if blk
  @models << {
    name:       name,
    table:      table,
    finders:    builder.finders,
    validators: builder.validators,
  }
end

.modelsObject



11
12
13
# File 'lib/fresco/model_builder.rb', line 11

def self.models
  @models
end

.path_to_class(file, root) ⇒ Object

— Build-time naming helpers ———————————-

File paths under app/actions/ map to Ruby constants by segment: “users/show” → “Users::Show”, “admin/api/sessions/new” →“Admin::Api::Sessions::New”. Each path segment is split on underscores and CamelCased; “::” joins the segments back.

‘const_set_path` exists because `Object.const_set` only accepts a bare name — passing “Users::Show” raises. We walk the namespace, creating Module shells where missing, then set the leaf constant on the resolved parent.



30
31
32
33
# File 'lib/fresco.rb', line 30

def self.path_to_class(file, root)
  rel = file.sub(%r{\A#{Regexp.escape(root)}/?}, "").sub(/\.rb\z/, "")
  rel.split("/").map { |seg| seg.split("_").map(&:capitalize).join }.join("::")
end

.reset_db_sql_stats!Object



150
151
152
153
# File 'lib/fresco/runtime/runtime.rb', line 150

def self.reset_db_sql_stats!
  @db_sql_total_micros = 0
  @db_sql_count        = 0
end

.schema(&blk) ⇒ Object



25
26
27
28
29
# File 'lib/fresco/schema_builder.rb', line 25

def self.schema(&blk)
  builder = Fresco::SchemaBuilder.new
  builder.instance_eval(&blk)
  @schema_tables = builder.tables
end

.schema_tablesObject



21
22
23
# File 'lib/fresco/schema_builder.rb', line 21

def self.schema_tables
  @schema_tables
end

.session_secretObject



66
67
68
# File 'lib/fresco/runtime/runtime.rb', line 66

def self.session_secret
  @session_secret
end

.session_secret=(s = "") ⇒ Object



70
71
72
# File 'lib/fresco/runtime/runtime.rb', line 70

def self.session_secret=(s = "")
  @session_secret = s
end

.set_session_secret(s = "") ⇒ Object

Non-‘=` setter, used by config/app.rb. Spinel’s codegen for top-level ‘Fresco.session_secret = local` rewrites the call into a direct `cst_Fresco_session_secret = sp_box_str(local)` ivar write, but the ivar slot is declared `const char *` — the `sp_box_str` wrap produces a C type mismatch. Routing through a plain method bypasses the rewrite and goes through the function-call path (which handles the const-char-* assignment correctly, as in `def self.session_secret=`).



82
83
84
# File 'lib/fresco/runtime/runtime.rb', line 82

def self.set_session_secret(s = "")
  @session_secret = s
end