Class: Tram::Policy::Generator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Tram::Policy::Generator
- Includes:
- Thor::Actions
- Defined in:
- lib/tram/policy/generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate_class ⇒ Object
- #generate_locales ⇒ Object
- #generate_spec ⇒ Object
- #set_available_locales ⇒ Object
Class Method Details
.source_root ⇒ Object
35 36 37 |
# File 'lib/tram/policy/generator.rb', line 35 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#generate_class ⇒ Object
48 49 50 |
# File 'lib/tram/policy/generator.rb', line 48 def generate_class template "generator/policy.erb", "app/policies/#{file}.rb" end |
#generate_locales ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/tram/policy/generator.rb', line 52 def generate_locales available_locales.each do |locale| @locale = locale add_locale localize_policy parsed_validators.sort_by { |v| v[:key] } .each { |validator| localize_validator(validator) } end end |
#generate_spec ⇒ Object
62 63 64 |
# File 'lib/tram/policy/generator.rb', line 62 def generate_spec template "generator/policy_spec.erb", "spec/policies/#{file}_spec.rb" end |
#set_available_locales ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/tram/policy/generator.rb', line 39 def set_available_locales @available_locales = \ if Array([:locales]).any? [:locales] else ask("Enter available locales for translation:").scan(/\w{2}/) end end |