Class: Ruact::Generators::ScaffoldGenerator::ScaffoldAttribute
- Inherits:
-
Object
- Object
- Ruact::Generators::ScaffoldGenerator::ScaffoldAttribute
- Defined in:
- lib/generators/ruact/scaffold/scaffold_attribute.rb
Overview
A single scaffold attribute (name + AR type) with the view-model helpers
the templates consume. references columns address <name>_id. Lives in
its own file to keep Ruact::Generators::ScaffoldGenerator within its class-length budget;
reopens the generator class so TYPE_MAP resolves by lexical scope.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #boolean? ⇒ Boolean
-
#column_kind ⇒ Object
The DataTable cell renderer kind (Story 10.2 AC1): :badge → boolean → Badge "Yes"/"No" :numeric → integer/float/decimal/references → right-aligned numeric :date → date/datetime → locale-formatted :text → string/text → plain text.
-
#column_name ⇒ Object
The wire/DB column the controller params + serialized rows use.
- #control ⇒ Object
-
#date? ⇒ Boolean
date/datetime — the List sorts these columns by epoch time (Story 10.2b).
-
#initialize(name, type) ⇒ ScaffoldAttribute
constructor
A new instance of ScaffoldAttribute.
-
#js_setter ⇒ Object
The React
useStatesetter name (authorId→setAuthorId). -
#js_var ⇒ Object
camelCase JS identifier for the column (
author_id→authorId). -
#options_ivar ⇒ Object
references only — the controller ivar / view local holding the capped parent options (
author→author_options). -
#options_prop ⇒ Object
references only — the camelCase prop the view passes and the Form reads (
author→authorOptions,blog_post→blogPostOptions). - #reference? ⇒ Boolean
-
#reference_class_name ⇒ Object
references only — the parent model constant (
author→Author,blog_post→BlogPost), used by the controller's options loader. -
#shadcn_control ⇒ Object
The shadcn Form control this attribute renders as (Story 10.3 AC1): :input → string → :textarea → text →
- #ts_type ⇒ Object
Constructor Details
#initialize(name, type) ⇒ ScaffoldAttribute
Returns a new instance of ScaffoldAttribute.
15 16 17 18 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 15 def initialize(name, type) @name = name @type = type end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 13 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 13 def type @type end |
Instance Method Details
#boolean? ⇒ Boolean
33 34 35 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 33 def boolean? type == "boolean" end |
#column_kind ⇒ Object
The DataTable cell renderer kind (Story 10.2 AC1):
:badge → boolean → Badge "Yes"/"No"
:numeric → integer/float/decimal/references → right-aligned numeric
:date → date/datetime → locale-formatted
:text → string/text → plain text
47 48 49 50 51 52 53 54 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 47 def column_kind case type when "boolean" then :badge when "integer", "float", "decimal", "references" then :numeric when "date", "datetime" then :date else :text end end |
#column_name ⇒ Object
The wire/DB column the controller params + serialized rows use.
21 22 23 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 21 def column_name reference? ? "#{name}_id" : name end |
#control ⇒ Object
29 30 31 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 29 def control TYPE_MAP.fetch(type)[:control] end |
#date? ⇒ Boolean
date/datetime — the List sorts these columns by epoch time (Story 10.2b).
38 39 40 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 38 def date? column_kind == :date end |
#js_setter ⇒ Object
The React useState setter name (authorId → setAuthorId).
108 109 110 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 108 def js_setter "set#{js_var.sub(/\A./, &:upcase)}" end |
#js_var ⇒ Object
camelCase JS identifier for the column (author_id → authorId).
102 103 104 105 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 102 def js_var parts = column_name.split("_") (parts.first(1) + parts.drop(1).map(&:capitalize)).join end |
#options_ivar ⇒ Object
references only — the controller ivar / view local holding the capped
parent options (author → author_options).
86 87 88 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 86 def "#{name}_options" end |
#options_prop ⇒ Object
references only — the camelCase prop the view passes and the Form reads
(author → authorOptions, blog_post → blogPostOptions).
92 93 94 95 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 92 def parts = name.split("_") "#{(parts.first(1) + parts.drop(1).map(&:capitalize)).join}Options" end |
#reference? ⇒ Boolean
97 98 99 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 97 def reference? type == "references" end |
#reference_class_name ⇒ Object
references only — the parent model constant (author → Author,
blog_post → BlogPost), used by the controller's options loader.
80 81 82 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 80 def reference_class_name name.camelize end |
#shadcn_control ⇒ Object
The shadcn Form control this attribute renders as (Story 10.3 AC1):
:input → string → <Input type="text">
:textarea → text → <Textarea>
:switch → boolean → <Switch>
:number → integer/float/decimal → <Input type="number">
:date → date → <Input type="date">
:datetime → datetime → <Input type="datetime-local">
:select → references → <Select> of parent options
The :input/:number/:date/:datetime kinds all render an ; the
concrete type= attribute comes from html_input_type (FormHelpers).
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 66 def shadcn_control case type when "text" then :textarea when "boolean" then :switch when "integer", "float", "decimal" then :number when "date" then :date when "datetime" then :datetime when "references" then :select else :input end end |
#ts_type ⇒ Object
25 26 27 |
# File 'lib/generators/ruact/scaffold/scaffold_attribute.rb', line 25 def ts_type TYPE_MAP.fetch(type)[:ts] end |