Class: DynamicFields::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_fields/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_or_fields, options = {}) ⇒ Index

Returns a new instance of Index.



5
6
7
8
9
10
# File 'lib/dynamic_fields/index.rb', line 5

def initialize field_or_fields, options={}
  @fields  = field_or_fields   
  @name    = options[:name]
  @unique  = options.delete(:unique) == true
  @options = options
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



3
4
5
# File 'lib/dynamic_fields/index.rb', line 3

def fields
  @fields
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/dynamic_fields/index.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/dynamic_fields/index.rb', line 3

def options
  @options
end

Instance Method Details

#idObject



12
13
14
# File 'lib/dynamic_fields/index.rb', line 12

def id
  name
end

#migration_string_for(table_state, action) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dynamic_fields/index.rb', line 24

def migration_string_for table_state, action
  args = []
  case action = action.to_sym
  when :add
    args << (fields.is_a?(Array) ? fields : fields.to_sym).inspect
    args << ":name => #{to_s.inspect}"
    args << ":unique => true" if unique?
  when :remove
    args << ":name => #{to_s.inspect}"
  end
  args.join(', ').gsub('\\', '')
end

#to_sObject



16
17
18
# File 'lib/dynamic_fields/index.rb', line 16

def to_s
  name.to_s
end

#unique?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dynamic_fields/index.rb', line 20

def unique?
  @unique == true
end