Class: Shaf::Generator::Profile
- Inherits:
-
Base
- Object
- Base
- Shaf::Generator::Profile
show all
- Defined in:
- lib/shaf/generator/profile.rb
Instance Attribute Summary
Attributes inherited from Base
#args, #options
Instance Method Summary
collapse
Methods inherited from Base
identified_by, identifier, #identifier, inherited, #initialize, options, usage
Instance Method Details
#attributes ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/shaf/generator/profile.rb', line 23
def attributes
args[1..-1].map do |attr|
name, type = attr.split(':')
type ||= 'String'
[name, type.capitalize]
end
end
|
#call ⇒ Object
7
8
9
|
# File 'lib/shaf/generator/profile.rb', line 7
def call
create_profile
end
|
#create_profile ⇒ Object
31
32
33
34
35
|
# File 'lib/shaf/generator/profile.rb', line 31
def create_profile
content = render(template, opts)
content = wrap_in_module(content, module_name, search: 'class \w')
write_output(target, content)
end
|
#opts ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/shaf/generator/profile.rb', line 37
def opts
{
profile_name: name,
profile_class_name: "#{model_class_name}",
attributes: attributes,
resource_name: resource_name,
}
end
|
#target_dir ⇒ Object
15
16
17
|
# File 'lib/shaf/generator/profile.rb', line 15
def target_dir
'api/profiles'
end
|
#target_name ⇒ Object
19
20
21
|
# File 'lib/shaf/generator/profile.rb', line 19
def target_name
"#{name}.rb"
end
|
#template ⇒ Object
11
12
13
|
# File 'lib/shaf/generator/profile.rb', line 11
def template
'api/profile.rb'
end
|