Sha256: 958cdee5ea15e06bbf84ffd62c3eedfb84048b58c6951b238fde54aef93a3093

Contents?: true

Size: 995 Bytes

Versions: 1

Compression:

Stored size: 995 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'
require 'minarai/actions/rbenv'

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

1 entries across 1 versions & 1 rubygems

Version Path
minarai-0.0.3 lib/minarai/action_builder.rb