Class: TableStructure::Schema::Columns::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/table_structure/schema/columns/attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, key:, value:, size:) ⇒ Attributes

Returns a new instance of Attributes.



9
10
11
12
13
14
15
16
# File 'lib/table_structure/schema/columns/attributes.rb', line 9

def initialize(name:, key:, value:, size:)
  @name_callable = Utils.callable?(name)
  @name = @name_callable ? name : proc { name }
  @keys = optimize_size([key].flatten, size)
  @value_callable = Utils.callable?(value)
  @value = @value_callable ? value : proc { value }
  @size = size
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



7
8
9
# File 'lib/table_structure/schema/columns/attributes.rb', line 7

def keys
  @keys
end

#sizeObject (readonly)

Returns the value of attribute size.



7
8
9
# File 'lib/table_structure/schema/columns/attributes.rb', line 7

def size
  @size
end

Instance Method Details

#name_callable?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/table_structure/schema/columns/attributes.rb', line 28

def name_callable?
  @name_callable
end

#names(context, table_context) ⇒ Object



18
19
20
21
# File 'lib/table_structure/schema/columns/attributes.rb', line 18

def names(context, table_context)
  names = @name.call(context, table_context)
  optimize_size(names, @size)
end

#value_callable?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/table_structure/schema/columns/attributes.rb', line 32

def value_callable?
  @value_callable
end

#values(context, table_context) ⇒ Object



23
24
25
26
# File 'lib/table_structure/schema/columns/attributes.rb', line 23

def values(context, table_context)
  values = @value.call(context, table_context)
  optimize_size(values, @size)
end