Sha256: 782216b5d44800d970e5cd84a823763260651e368232c593aac423262a34e0fa

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 KB

Contents

module Onoma
  class Migration
    module Actions
      class ItemCreation < Onoma::Migration::Actions::Base
        attr_reader :nomenclature, :name, :options
        def initialize(element)
          raise 'Need item attribute' unless element['item']
          name = element['item'].split('#')
          @nomenclature = name.first
          @name = name.second
          @options = element.attributes.delete_if do |k, _v|
            k =~ /name(:[a-z]{3})?/ || %w[item parent nomenclature].include?(k)
          end.each_with_object({}) do |(k, v), h|
            h[k.to_sym] = v.to_s
          end
          @options[:parent] = element['parent'].to_sym if element.key?('parent')
        end

        def options?
          @options.any?
        end

        def label
          "create_item #{@nomenclature}##{@name}" + (@options.any? ? "(#{@options.simple_print})" : '')
        end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
onoma-0.3.4 lib/onoma/migration/actions/item_creation.rb
onoma-0.3.3 lib/onoma/migration/actions/item_creation.rb
onoma-0.3.1 lib/onoma/migration/actions/item_creation.rb
onoma-0.2.2 lib/onoma/migration/actions/item_creation.rb
onoma-0.2.1 lib/onoma/migration/actions/item_creation.rb
onoma-0.2.0 lib/onoma/migration/actions/item_creation.rb