Sha256: b2450207e80c6c0fd0f842e8a759f1a4e97131de1e5ea7c3053d56fa78e8e947

Contents?: true

Size: 1.38 KB

Versions: 11

Compression:

Stored size: 1.38 KB

Contents

require 'active_support'
require 'active_support/core_ext'
require 'thor'
require 'eucalypt/helpers'

module Eucalypt
  module Generators
    class Policy < Thor::Group
      include Thor::Actions
      include Eucalypt::Helpers

      def self.source_root
        File.join File.dirname(__dir__), 'templates'
      end

      def generate(headless:, name:)
        policy = Inflect.new(:policy, name)
        config = {class_name: policy.class_name, resource: policy.resource, constant: policy.constant, headless: headless}
        template 'policy.tt', policy.file_path, config
      end

      def generate_policy_role_model(policy:)
        roles_directory = File.join 'app', 'models', 'roles'
        role_model_file = File.join roles_directory, "#{policy.resource}_role.rb"

        empty_directory roles_directory unless File.directory? roles_directory

        config = {constant: policy.constant}
        template 'policy_role.tt', role_model_file, config
      end

      def generate_policy_roles_migration(policy:)
        sleep 1
        migration = Eucalypt::Helpers::Migration[title: "create_#{policy}_roles", template: 'create_policy_roles_migration.tt']
        return unless migration.create_anyway? if migration.exists?
        config = {migration_title: migration.title.camelize, policy: policy}
        template migration.template, migration.file_path, config
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
eucalypt-0.8.0 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.7.2 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.7.1 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.7.0 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.6.2 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.6.1 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.6.0 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.5.4 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.5.3 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.5.2 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb
eucalypt-0.5.1 lib/eucalypt/security/namespaces/security-policy/generators/policy.rb