Class: Nomen::Migration::Actions::PropertyCreation

Inherits:
Base
  • Object
show all
Defined in:
lib/nomen/migration/actions/property_creation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

action_name, #action_name

Constructor Details

#initialize(element) ⇒ PropertyCreation

Returns a new instance of PropertyCreation.


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nomen/migration/actions/property_creation.rb', line 6

def initialize(element)
  name = element['property'].split('.')
  @nomenclature = name.first
  @name = name.second
  @type = element['type'].to_sym
  unless Nomen::PROPERTY_TYPES.include?(@type)
    raise ArgumentError, "Property #{name} type is unknown: #{@type.inspect}"
  end
  @options = {}
  if element.has_attribute?('fallbacks')
    @options[:fallbacks] = element.attr('fallbacks').to_s.strip.split(/[[:space:]]*\,[[:space:]]*/).map(&:to_sym)
  end
  if element.has_attribute?('default')
    @options[:default] = element.attr('default').to_sym
  end
  @options[:required] = !!(element.attr('required').to_s == 'true')
  # @options[:inherit]  = !!(element.attr('inherit').to_s == 'true')
  if element.has_attribute?('choices')
    if type == :choice || type == :choice_list
      @options[:choices] = element.attr('choices').to_s.strip.split(/[[:space:]]*\,[[:space:]]*/).map(&:to_sym)
    elsif type == :item || type == :item_list
      @options[:choices] = element.attr('choices').to_s.strip.to_sym
    end
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/nomen/migration/actions/property_creation.rb', line 5

def name
  @name
end

#nomenclatureObject (readonly)

Returns the value of attribute nomenclature


5
6
7
# File 'lib/nomen/migration/actions/property_creation.rb', line 5

def nomenclature
  @nomenclature
end

#optionsObject (readonly)

Returns the value of attribute options


5
6
7
# File 'lib/nomen/migration/actions/property_creation.rb', line 5

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type


5
6
7
# File 'lib/nomen/migration/actions/property_creation.rb', line 5

def type
  @type
end

Instance Method Details

#human_nameObject


32
33
34
35
36
37
38
39
# File 'lib/nomen/migration/actions/property_creation.rb', line 32

def human_name
  updates = []
  updates << "#{@name} as name"
  @options.each do |k, v|
    updates << "#{v} as #{k}"
  end
  sentence = "Create property #{@nomenclature}.#{@name} with " + updates.to_sentence
end