Class: Shaf::Generator::Profile

Inherits:
Base
  • Object
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

Constructor Details

This class inherits a constructor from Shaf::Generator::Base

Instance Method Details

#attributesObject



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

#callObject



7
8
9
# File 'lib/shaf/generator/profile.rb', line 7

def call
  create_profile
end

#create_profileObject



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

#optsObject



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_dirObject



15
16
17
# File 'lib/shaf/generator/profile.rb', line 15

def target_dir
  'api/profiles'
end

#target_nameObject



19
20
21
# File 'lib/shaf/generator/profile.rb', line 19

def target_name
  "#{name}.rb"
end

#templateObject



11
12
13
# File 'lib/shaf/generator/profile.rb', line 11

def template
  'api/profile.rb'
end