Class: VersionedStore::Stores::Schema::RecordContext

Inherits:
Object
  • Object
show all
Defined in:
lib/versioned_store/stores/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_instance, record_name) ⇒ RecordContext

Returns a new instance of RecordContext.



13
14
15
16
17
# File 'lib/versioned_store/stores/schema.rb', line 13

def initialize(schema_instance, record_name)
  @schema_instance = schema_instance
  @record_name = record_name
  @table_name = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



34
35
# File 'lib/versioned_store/stores/schema.rb', line 34

def method_missing(...)
end

Instance Attribute Details

#record_nameObject (readonly)

Returns the value of attribute record_name.



11
12
13
# File 'lib/versioned_store/stores/schema.rb', line 11

def record_name
  @record_name
end

#schema_instanceObject (readonly)

Returns the value of attribute schema_instance.



11
12
13
# File 'lib/versioned_store/stores/schema.rb', line 11

def schema_instance
  @schema_instance
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



11
12
13
# File 'lib/versioned_store/stores/schema.rb', line 11

def table_name
  @table_name
end

Instance Method Details

#respond_to_missing?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/versioned_store/stores/schema.rb', line 37

def respond_to_missing?(...)
  true
end

#schema(table_name = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/versioned_store/stores/schema.rb', line 19

def schema(table_name = nil, &block)
  # If no table name provided, infer from record name
  if table_name.nil?
    name_str = record_name.to_s
    table_name = (name_str.end_with?('s') ? name_str : "#{name_str}s").to_sym
  end

  # Store the table name for later use
  @table_name = table_name

  # Collect all schema blocks for a table
  schema_instance.schema_blocks[table_name] ||= []
  schema_instance.schema_blocks[table_name] << block if block
end