Module: ScopeHelpers

Included in:
Ingoweiss::ScaffoldControllerGenerator, Ingoweiss::ScaffoldGenerator, Ingoweiss::ScaffoldViewsGenerator
Defined in:
lib/generators/ingoweiss/helpers/scope_helpers.rb

Instance Method Summary collapse

Instance Method Details

#instance_variable_scope(variable = nil) ⇒ Object

Example: ‘@post, @comment, approval’



30
31
32
33
34
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 30

def instance_variable_scope(variable=nil)
  instance_variables = scope.collect{|s| '@' + s.singularize}
  instance_variables << variable if variable
  instance_variables.join(', ')
end

#scopeObject



3
4
5
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 3

def scope
  options[:scope]
end

#scope_prefixObject

Example: ‘post_comment_’ for post_comment_approval_path



20
21
22
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 20

def scope_prefix
  scope.collect{|s| s.singularize + '_'}.join
end

#scoped?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 7

def scoped?
  scope.any?
end

#scoped_controller_class_nameObject

Examples: ‘PostComments’, ‘PostCommentApproval’



37
38
39
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 37

def scoped_controller_class_name
  scoped_controller_plural_name.camelize
end

#scoped_controller_plural_nameObject

Examples: ‘post_comments’, ‘post_comment_approval’



25
26
27
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 25

def scoped_controller_plural_name
  scope_prefix + (options[:singleton] ? singular_name : plural_name)
end

#singleton?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 15

def singleton?
  options[:singleton]
end

#unscoped?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/generators/ingoweiss/helpers/scope_helpers.rb', line 11

def unscoped?
  !scoped?
end