Class: Shaf::Generator::Policy
- Inherits:
-
Base
- Object
- Base
- Shaf::Generator::Policy
show all
- Defined in:
- lib/shaf/generator/policy.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
29
30
31
|
# File 'lib/shaf/generator/policy.rb', line 29
def attributes
args[1..-1].map { |attr| "attribute :#{attr}" }
end
|
#call ⇒ Object
7
8
9
|
# File 'lib/shaf/generator/policy.rb', line 7
def call
create_policy
end
|
#create_policy ⇒ Object
23
24
25
26
27
|
# File 'lib/shaf/generator/policy.rb', line 23
def create_policy
content = render(template, opts)
content = wrap_in_module(content, module_name)
write_output(target, content)
end
|
#opts ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/shaf/generator/policy.rb', line 33
def opts
{
policy_class_name: "#{model_class_name}Policy",
name: name,
attributes: attributes,
}
end
|
#target_dir ⇒ Object
15
16
17
|
# File 'lib/shaf/generator/policy.rb', line 15
def target_dir
'api/policies'
end
|
#target_name ⇒ Object
19
20
21
|
# File 'lib/shaf/generator/policy.rb', line 19
def target_name
"#{name}_policy.rb"
end
|
#template ⇒ Object
11
12
13
|
# File 'lib/shaf/generator/policy.rb', line 11
def template
'api/policy.rb'
end
|