Class: MegaBar::Field

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/mega_bar/field.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#block_idObject

Returns the value of attribute block_id.



6
7
8
# File 'app/models/mega_bar/field.rb', line 6

def block_id
  @block_id
end

#edit_field_displayObject

Returns the value of attribute edit_field_display.



6
7
8
# File 'app/models/mega_bar/field.rb', line 6

def edit_field_display
  @edit_field_display
end

#index_field_displayObject

Returns the value of attribute index_field_display.



6
7
8
# File 'app/models/mega_bar/field.rb', line 6

def index_field_display
  @index_field_display
end

#model_display_idsObject

Returns the value of attribute model_display_ids.



6
7
8
# File 'app/models/mega_bar/field.rb', line 6

def model_display_ids
  @model_display_ids
end

#new_field_displayObject

Returns the value of attribute new_field_display.



6
7
8
# File 'app/models/mega_bar/field.rb', line 6

def new_field_display
  @new_field_display
end

#show_field_displayObject

Returns the value of attribute show_field_display.



6
7
8
# File 'app/models/mega_bar/field.rb', line 6

def show_field_display
  @show_field_display
end

Class Method Details

.deterministic_id(name, field_type, model_id = nil) ⇒ Object

Deterministic ID generation for Fields ID range: 1000-1999



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/mega_bar/field.rb', line 19

def self.deterministic_id(name, field_type, model_id = nil)
  # Include model_id to make fields unique per model
  identifier = model_id ? "#{name}_#{field_type}_#{model_id}" : "#{name}_#{field_type}"
  hash = Digest::MD5.hexdigest(identifier)
  base_id = 1000 + (hash.to_i(16) % 1000)
  
  # Check for collisions and increment if needed
  while MegaBar::Field.exists?(id: base_id)
    base_id += 1
    break if base_id >= 2000  # Don't overflow into next range
  end
  
  base_id
end