Module: ReduxGen::Validations
- Defined in:
- lib/redux_gen/validations.rb
Class Method Summary collapse
- .component_path(component, name) ⇒ Object
- .directory(component) ⇒ Object
- .sanitize(component, name) ⇒ Object
- .validate(component) ⇒ Object
- .validate_directory_for(component) ⇒ Object
Class Method Details
.component_path(component, name) ⇒ Object
16 17 18 |
# File 'lib/redux_gen/validations.rb', line 16 def self.component_path(component, name) "#{directory(component)}/#{sanitize(component, name)}.js" end |
.directory(component) ⇒ Object
8 9 10 |
# File 'lib/redux_gen/validations.rb', line 8 def self.directory component component == "middleware" ? component : "#{component}s" end |
.sanitize(component, name) ⇒ Object
20 21 22 23 24 |
# File 'lib/redux_gen/validations.rb', line 20 def self.sanitize component, name first = name.split.first rest = name.split[1..-1].map(&:capitalize).join (component == "component" ? first.capitalize : first) + rest end |
.validate(component) ⇒ Object
3 4 5 6 |
# File 'lib/redux_gen/validations.rb', line 3 def self.validate component components = ["action", "component", "reducer", "middleware"] raise ArgumentError unless components.include? component end |
.validate_directory_for(component) ⇒ Object
12 13 14 |
# File 'lib/redux_gen/validations.rb', line 12 def self.validate_directory_for component Dir.mkdir directory(component) unless Dir.exists? directory(component) end |