Sha256: c72c37f12907a3f4524bd20da8c01c91e9a10817f11ab270e0c1ed9e4041364e

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

require 'active_support/core_ext/string/inflections'
require 'minarai/actions/git'
require 'minarai/actions/file'
require 'minarai/actions/homebrew'
require 'minarai/actions/homebrew_cask'
require 'minarai/actions/link'
require 'minarai/actions/unknown'
require 'minarai/actions/directory'
require 'minarai/actions/url_get'

module Minarai
  class ActionBuilder
    def initialize(attirbutes)
      @attirbutes = attirbutes
    end

    def build
      action_class.new(@attirbutes)
    end

    private

    def action_class
      if known_action_type?
        Minarai::Actions.const_get(action_class_name, false)
      else
        Minarai::Actions::Unknown
      end
    end

    def known_action_type?
      has_type? && Minarai::Actions.constants.include?(action_class_name.to_sym)
    end

    def action_class_name
      type.camelize
    end

    def type
      @attirbutes['type']
    end

    def has_type?
      !!@attirbutes['type']
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minarai-0.0.2 lib/minarai/action_builder.rb
minarai-0.0.1 lib/minarai/action_builder.rb