Module: Faalis::Generators::Concerns::Parent

Included in:
DashboardScaffold
Defined in:
lib/faalis/generators/concerns/parent.rb

Overview

This concern adds the methods needed to support nested resource in any dashboad generators. This module adds parents key to jsonfile which is an array of resource parents in right order. For example if we have a nested resource like:

resources :blogs do
  resources :categories do
    resources :posts
  end
end

And we want to create an dashboard scaffold for post resource we have to add parent key to our json file like this:

...
"parents": [
    "blog",
    "category"
]
...

Please pay attention to singular form of name of parents in json defination

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) parent? (private)

check for parent

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/faalis/generators/concerns/parent.rb', line 35

def parent?
  if resource_data.include? 'parents'
    return true unless resource_data['parents'].nil?
  end
  false
end

- (Object) parents (private)

Return an array of resource parents



48
49
50
51
52
53
54
55
56
57
# File 'lib/faalis/generators/concerns/parent.rb', line 48

def parents
  if parent?
    _parents = resource_data['parents']
    _parents.collect do |p|
      trim_parent_path(p)
    end
  else
    []
  end
end

- (Object) trim_parent_path(path) (private)

Remove the starting slash from the given parent path



43
44
45
# File 'lib/faalis/generators/concerns/parent.rb', line 43

def trim_parent_path(path)
  path.gsub(/^\//, '')
end