Sha256: 714dc6d33bee4c2d6f83f24f42026c2fb5372b4db350104e704fe0051b9a90b4

Contents?: true

Size: 918 Bytes

Versions: 19

Compression:

Stored size: 918 Bytes

Contents

require_relative "./file_card_creator/script_card"
require_relative "./file_card_creator/style_card"
require_relative "./file_card_creator/haml_card"
require_relative "./file_card_creator/abstract_file_card"

class Card
  # A Factory class
  # It chooses the class to create the file card according to the given type.
  class FileCardCreator
    CARD_CLASSES = [StyleCard, ScriptCard, HamlCard].freeze

    attr_reader :creator

    def initialize mod, name, type, codename, force
      card_class = FileCardCreator.card_class type
      unless card_class
        raise "'#{type}' is not a valid type. "\
              "Please choose between js, coffee, css, scss and haml", :red
      end

      @creator = card_class.new mod, name, type, codename: codename, force: force
    end

    def self.card_class type
      CARD_CLASSES.find { |cc| cc.valid_type? type }
    end

    delegate :create, to: :creator
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
card-1.103.2 lib/card/tasks/card/file_card_creator.rb
card-1.103.1 lib/card/tasks/card/file_card_creator.rb
card-1.103.0 lib/card/tasks/card/file_card_creator.rb
card-1.101.7 lib/card/tasks/card/file_card_creator.rb
card-1.102.0 lib/card/tasks/card/file_card_creator.rb
card-1.101.6 lib/card/tasks/card/file_card_creator.rb
card-1.101.5 lib/card/tasks/card/file_card_creator.rb
card-1.101.4 lib/card/tasks/card/file_card_creator.rb
card-1.101.3 lib/card/tasks/card/file_card_creator.rb
card-1.101.2 lib/card/tasks/card/file_card_creator.rb
card-1.101.1 lib/card/tasks/card/file_card_creator.rb
card-1.101.0 lib/card/tasks/card/file_card_creator.rb
card-1.100.0 lib/card/tasks/card/file_card_creator.rb
card-1.99.6 lib/card/tasks/card/file_card_creator.rb
card-1.99.5 lib/card/tasks/card/file_card_creator.rb
card-1.99.4 lib/card/tasks/card/file_card_creator.rb
card-1.99.3 lib/card/tasks/card/file_card_creator.rb
card-1.99.2 lib/card/tasks/card/file_card_creator.rb
card-1.99.1 lib/card/tasks/card/file_card_creator.rb