Class: Rooq::Table
- Inherits:
-
Object
show all
- Extended by:
- T::Sig
- Defined in:
- lib/rooq/table.rb
Defined Under Namespace
Classes: TableBuilder
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, &block) ⇒ void
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rooq/table.rb', line 17
def initialize(name, &block)
@name = name
@fields = T.let({}, T::Hash[Symbol, Field])
@field_accessors = T.let({}, T::Hash[Symbol, Field])
if block_given?
builder = TableBuilder.new(self)
block.call(builder)
end
@fields.freeze
freeze
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Field
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rooq/table.rb', line 37
def method_missing(method_name, *args)
field_name = method_name.to_s.downcase.to_sym
if @fields.key?(field_name)
T.must(@fields[field_name])
else
available = @fields.keys.join(", ")
raise ValidationError, "Unknown field '#{field_name}' on table '#{@name}'. Available fields: #{available}"
end
end
|
Instance Attribute Details
#fields ⇒ Hash{Symbol => Field}
14
15
16
|
# File 'lib/rooq/table.rb', line 14
def fields
@fields
end
|
#name ⇒ Symbol
11
12
13
|
# File 'lib/rooq/table.rb', line 11
def name
@name
end
|
Instance Method Details
#asterisk ⇒ Array<Field>
32
33
34
|
# File 'lib/rooq/table.rb', line 32
def asterisk
@fields.values
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
49
50
51
52
|
# File 'lib/rooq/table.rb', line 49
def respond_to_missing?(method_name, include_private = false)
field_name = method_name.to_s.downcase.to_sym
@fields.key?(field_name) || super
end
|