Sha256: 2c36a0db1558cbb5e786014d7c922f319a1b88765be827b42654e1444633ff2c

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

module Onoma
  module Migration
    module Actions
      class PropertyCreation < Onoma::Migration::Actions::Base
        attr_reader :nomenclature, :name, :type, :options
        def initialize(element)
          name = element['property'].split('.')
          @nomenclature = name.first
          @name = name.second
          @type = element['type'].to_sym
          unless Onoma::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

        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
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
onoma-0.4.2 lib/onoma/migration/actions/property_creation.rb
onoma-0.5.1 lib/onoma/migration/actions/property_creation.rb
onoma-0.5.0 lib/onoma/migration/actions/property_creation.rb
onoma-0.4.1 lib/onoma/migration/actions/property_creation.rb
onoma-0.4.0 lib/onoma/migration/actions/property_creation.rb