Class: Shaf::Generator::Policy

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

Constructor Details

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

Instance Method Details

#attributesObject



29
30
31
# File 'lib/shaf/generator/policy.rb', line 29

def attributes
  args[1..-1].map { |attr| "attribute :#{attr}" }
end

#callObject



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

def call
  create_policy
end

#create_policyObject



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

#optsObject



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_dirObject



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

def target_dir
  'api/policies'
end

#target_nameObject



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

def target_name
  "#{name}_policy.rb"
end

#templateObject



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

def template
  'api/policy.rb'
end