Class: Infold::BaseWriter
- Inherits:
-
Object
- Object
- Infold::BaseWriter
show all
- Defined in:
- lib/infold/writers/base_writer.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource) ⇒ BaseWriter
Returns a new instance of BaseWriter.
6
7
8
|
# File 'lib/infold/writers/base_writer.rb', line 6
def initialize(resource)
@resource = resource
end
|
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
4
5
6
|
# File 'lib/infold/writers/base_writer.rb', line 4
def resource
@resource
end
|
Instance Method Details
#edit_path(object) ⇒ Object
30
31
32
|
# File 'lib/infold/writers/base_writer.rb', line 30
def edit_path(object)
"edit_admin_#{resource_name(:snake)}_path(#{object})"
end
|
#indent(code, size, first_row: false) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/infold/writers/base_writer.rb', line 10
def indent(code, size, first_row: false)
return unless code
indent = ' ' * size
code = code.each_line.map { |line| line.blank? ? line : "#{indent}#{line}" }.join
code.sub!(indent, '') unless first_row
code
end
|
#index_path ⇒ Object
18
19
20
|
# File 'lib/infold/writers/base_writer.rb', line 18
def index_path
"admin_#{resource_name(:snake, :multi)}_path"
end
|
#new_path ⇒ Object
22
23
24
|
# File 'lib/infold/writers/base_writer.rb', line 22
def new_path
"new_admin_#{resource_name(:snake)}_path"
end
|
#resource_name(*attr) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/infold/writers/base_writer.rb', line 34
def resource_name(*attr)
name = @resource.name.singularize.camelize
return name if attr.include?(:model)
return name.pluralize.underscore if attr.include?(:table)
name = name.underscore if attr.include?(:snake)
name = name.camelize if attr.include?(:camel)
name = name.singularize if attr.include?(:single)
name = name.pluralize if attr.include?(:multi)
name
end
|
#show_path(object) ⇒ Object
26
27
28
|
# File 'lib/infold/writers/base_writer.rb', line 26
def show_path(object)
"admin_#{resource_name(:snake)}_path(#{object})"
end
|