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
34 35 36 |
# File 'lib/tram/policy/generator.rb', line 34 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#generate_class ⇒ Object
47 48 49 |
# File 'lib/tram/policy/generator.rb', line 47 def generate_class template "generator/policy.erb", "app/policies/#{file}.rb" end |
#generate_locales ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/tram/policy/generator.rb', line 51 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
61 62 63 |
# File 'lib/tram/policy/generator.rb', line 61 def generate_spec template "generator/policy_spec.erb", "spec/policies/#{file}_spec.rb" end |
#set_available_locales ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/tram/policy/generator.rb', line 38 def set_available_locales @available_locales = \ if Array([:locales]).any? [:locales] else ask("Enter available locales for translation:").scan(/\w{2}/) end end |