Class: Card::FileCardCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/card/tasks/card/file_card_creator.rb,
lib/card/tasks/card/file_card_creator/haml_card.rb,
lib/card/tasks/card/file_card_creator/style_card.rb,
lib/card/tasks/card/file_card_creator/script_card.rb,
lib/card/tasks/card/file_card_creator/output_helper.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card/source_file.rb,
lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb

Overview

A Factory class It chooses the class to create the file card according to the given type.

Defined Under Namespace

Modules: OutputHelper Classes: AbstractFileCard, HamlCard, ScriptCard, StyleCard

Constant Summary collapse

CARD_CLASSES =
[StyleCard, ScriptCard, HamlCard].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod, name, type, codename, force) ⇒ FileCardCreator

Returns a new instance of FileCardCreator.



14
15
16
17
18
19
20
21
22
# File 'lib/card/tasks/card/file_card_creator.rb', line 14

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

Instance Attribute Details

#creatorObject (readonly)

Returns the value of attribute creator.



12
13
14
# File 'lib/card/tasks/card/file_card_creator.rb', line 12

def creator
  @creator
end

Class Method Details

.card_class(type) ⇒ Object



24
25
26
# File 'lib/card/tasks/card/file_card_creator.rb', line 24

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