Class: ClientSideValidations::Generators::CopyAssetsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/client_side_validations/copy_assets_generator.rb

Direct Known Subclasses

InstallGenerator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.asset_directoryObject



15
16
17
18
19
20
21
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 15

def self.asset_directory
  if sprockets?
    "app#{Rails.configuration.assets.prefix}/javascripts"
  else
    'public/javascripts'
  end
end

.asset_file_namesObject



27
28
29
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 27

def self.asset_file_names
  assets.map { |asset| asset[:file] }.join(', ')
end

.assetsObject



23
24
25
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 23

def self.assets
  ClientSideValidations::Generators.assets
end

.copy_assets?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 31

def self.copy_assets?
  !sprockets? && !webpacker?
end

.installation_messageObject



43
44
45
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 43

def self.installation_message
  "Copies #{asset_file_names} to #{asset_directory}"
end

.sprockets?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 35

def self.sprockets?
  defined?(Sprockets)
end

.webpacker?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 39

def self.webpacker?
  defined?(Webpacker)
end

Instance Method Details

#copy_javascript_assetObject



6
7
8
9
10
11
12
13
# File 'lib/generators/client_side_validations/copy_assets_generator.rb', line 6

def copy_javascript_asset
  return unless instance_of?(CopyAssetsGenerator) || copy_assets?

  assets.each do |asset|
    source_paths << asset[:path]
    copy_file asset[:file], "#{asset_directory}/#{asset[:file]}"
  end
end