Sha256: 3c5846cc0e2c3153a6526a014da7568f533873ac9bec9a974cc8c3aad11c76d7

Contents?: true

Size: 878 Bytes

Versions: 4

Compression:

Stored size: 878 Bytes

Contents

module ScopeHelpers
  
  def scope
    options[:scope]
  end
  
  def scoped?
    scope.any?
  end
  
  def unscoped?
    !scoped?
  end
  
  def singleton?
    options[:singleton]
  end
  
  # Example: 'post_comment_' for post_comment_approval_path
  def scope_prefix
    scope.collect{|s| s.singularize + '_'}.join
  end
  
  # Examples: 'post_comments', 'post_comment_approval'
  def scoped_controller_plural_name
    scope_prefix + (options[:singleton] ? singular_name : plural_name)
  end
  
  # Example: '@post, @comment, approval'
  def instance_variable_scope(variable=nil)
    instance_variables = scope.collect{|s| '@' + s.singularize}
    instance_variables << variable if variable
    instance_variables.join(', ')
  end
  
  # Examples: 'PostComments', 'PostCommentApproval'
  def scoped_controller_class_name
    scoped_controller_plural_name.camelize
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ingoweiss_generators-0.0.6 lib/generators/ingoweiss/helpers/scope_helpers.rb
ingoweiss_generators-0.0.5 lib/generators/ingoweiss/helpers/scope_helpers.rb
ingoweiss_generators-0.0.4 lib/generators/ingoweiss/helpers/scope_helpers.rb
ingoweiss_generators-0.0.3 lib/generators/ingoweiss/helpers/scope_helpers.rb