Class: DryGenerator

Inherits:
Rails::Generator::NamedBase
  • Object
show all
Defined in:
lib/dry_generator.rb

Constant Summary collapse

HAS_WILL_PAGINATE =
defined?(WillPaginate)
HAS_FORMTASTIC =
defined?(Formtastic)
HAS_INHERITED_RESOURCES =
defined?(InheritedResources)
HAS_SHOULDA =
defined?(Shoulda)
HAS_RSPEC =
defined?(Rspec)
[
  "[field:type field:type ...]"
].freeze
[
  "[--skip-tests]",
  "[--shoulda]",
  "[--rspec]",
  "[--fixtures]",
  "[--fgirl]",
  "[--machinist]",
  "[--odaddy]"
].freeze
DEFAULT_ARGS =
{
  :actions => (CONFIG_ARGS['actions'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil),
  :formats => (CONFIG_ARGS['formats'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil)
}.freeze
DEFAULT_OPTIONS =
{
  :resourceful      => CONFIG_OPTIONS['resourceful']  || HAS_INHERITED_RESOURCES,
  :formtastic       => CONFIG_OPTIONS['formtastic']   || HAS_FORMTASTIC,
  :pagination       => CONFIG_OPTIONS['pagination']   || HAS_WILL_PAGINATE,
  :skip_tests       => !CONFIG_OPTIONS['tests']       || false,
  :skip_helpers     => !CONFIG_OPTIONS['helpers']     || false,
  :skip_views       => !CONFIG_OPTIONS['views']       || false,
  :layout           => CONFIG_OPTIONS['layout']       || false,
  :fixtures         => CONFIG_OPTIONS['fixtures']     || false,
  :factory_girl     => CONFIG_OPTIONS['factory_girl'] || CONFIG_OPTIONS['fgirl'] || false,
  :machinist        => CONFIG_OPTIONS['machinist']    || false,
  :object_daddy     => CONFIG_OPTIONS['object_daddy'] || CONFIG_OPTIONS['odaddy'] || false,
  :test_unit        => CONFIG_OPTIONS['test_unit']    || CONFIG_OPTIONS['tunit'] || false,
  :shoulda          => CONFIG_OPTIONS['shoulda']      || false,
  :rspec            => CONFIG_OPTIONS['rspec']        || false
}.freeze
TEST_PATHS =
{
  :test_unit        => 'test',
  :shoulda          => 'test',
  :rspec            => 'spec'
}.freeze
TEST_POST_FIX =
{
  :test_unit        => 'test',
  :shoulda          => 'test',
  :rspec            => 'spec'
}.freeze
DEFAULT_TEST_FRAMEWORK =
:test_unit
DEFAULT_FACTORY_FRAMEWORK =
:fixtures
TESTS_PATH =
File.join('test').freeze
FUNCTIONAL_TESTS_PATH =
{
  :test_unit  => 'functional',
  :shoulda    => 'functional',
  :rspec      => 'controllers'
}
UNIT_TESTS_PATH =
{
  :test_unit  => 'unit',
  :shoulda    => 'unit',
  :rspec      => 'models',
}
NON_ATTR_ARG_KEY_PREFIX =
'_'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ DryGenerator

Returns a new instance of DryGenerator.



88
89
90
91
92
93
94
# File 'lib/dry_generator.rb', line 88

def initialize(runtime_args, runtime_options = {})
  super(runtime_args, runtime_options)
  
  @test_framework = ( options[:test_framework] && options[:test_framework].to_sym ) || 
                    [:rspec,:test_unit,:shoulda].detect{|t|options[t]} || 
                    DEFAULT_TEST_FRAMEWORK
end

Instance Attribute Details

#factory_frameworkObject

Returns the value of attribute factory_framework.



84
85
86
# File 'lib/dry_generator.rb', line 84

def factory_framework
  @factory_framework
end

#test_frameworkObject

Returns the value of attribute test_framework.



84
85
86
# File 'lib/dry_generator.rb', line 84

def test_framework
  @test_framework
end

#view_template_formatObject

Returns the value of attribute view_template_format.



84
85
86
# File 'lib/dry_generator.rb', line 84

def view_template_format
  @view_template_format
end