rails_on_rails 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9aec4b266e7f61ad14210fe09eb89764ce1ab7c1a7eaf4bc0094184ec9514333
4
- data.tar.gz: 3bd294bff6581454db51d5070497251cd846afee26d58da128dc8f8e88afae55
3
+ metadata.gz: def0a26afcb4e426602daed0554d81f1acd45e78483ce1ef6f4029dc1d01059a
4
+ data.tar.gz: e83ab1ce79832d512214388f5887133f5950c8c63249c35f84efd97a9bf77837
5
5
  SHA512:
6
- metadata.gz: cb27e0dc37dbc6e93b16f554b7de241b006689cc262e954fa7acddfbfb0eaeeda049648a196473834e65145f1a4e76e3d9dc9c747dc04a5daca8770ce9fc919c
7
- data.tar.gz: ef0add1aa31752e2c1782fee187ac0c0e9fa4cda6c672b342c8ff28c7e2865661bb8ead980b5f22b0ecf473a2d065e8eb0fc782c033f8f8d5f034c564064fe2e
6
+ metadata.gz: 6eb78331f19755601704425ed262a9e4cb46861319bfb9da28d82792fb8c3e6bed7fc9c5169ac1968ed82a508d85fa8be29c4145253a653a8559ef973d99e834
7
+ data.tar.gz: 2a60b8a91c12920c572c74e7c43372566de62afa274d17977cef3abed6ebefcd87a6cbea7b29b360f11122b8651a232769142b9d97e352d825109e0d16603b45
@@ -0,0 +1,38 @@
1
+ class {{ MODEL }}Policy < ApplicationPolicy
2
+ attr_reader :user, :{{ MODEL_UNDERSCORE }}
3
+
4
+ def initialize(user, {{ MODEL_UNDERSCORE }})
5
+ @user = user
6
+ @{{ MODEL_UNDERSCORE }} = {{ MODEL_UNDERSCORE }}
7
+ end
8
+
9
+ def create?
10
+ if user.try(:admin?)
11
+ user.admin?
12
+ end
13
+ end
14
+
15
+ def index?
16
+ if user.try(:admin?)
17
+ user.admin?
18
+ end
19
+ end
20
+
21
+ def show?
22
+ if user.try(:admin?)
23
+ user.admin?
24
+ end
25
+ end
26
+
27
+ def update?
28
+ if user.try(:admin?)
29
+ user.admin?
30
+ end
31
+ end
32
+
33
+ def destroy?
34
+ if user.try(:admin?)
35
+ user.admin?
36
+ end
37
+ end
38
+ end
@@ -22,3 +22,14 @@ read_file = read_file.gsub! '{{ MODEL }}', MODEL_CAMEL_CASE
22
22
  read_file = read_file.gsub! '{{ GLOBAL_CONTROLLER }}', GLOBAL_CONTROLLER
23
23
 
24
24
  File.write(controller_path, read_file)
25
+
26
+ if Dir.exists?("#{Dir.pwd}/app/policies")
27
+ policy_template_path = "#{__dir__}/../generator_templates/policy.txt"
28
+ policy_path = "#{Dir.pwd}/app/policies/#{MODEL_SNAKE_CASE}_policy.rb"
29
+
30
+ policy_read_file = File.open(policy_template_path, 'r:UTF-8', &:read)
31
+ policy_read_file = policy_read_file.gsub! '{{ MODEL }}', MODEL_CAMEL_CASE
32
+ policy_read_file = policy_read_file.gsub! '{{ MODEL_UNDERSCORE }}', MODEL_SNAKE_CASE
33
+ File.write(policy_path, policy_read_file)
34
+ puts "Generated policy"
35
+ end
@@ -2,7 +2,7 @@ class CLIOptions
2
2
  class <<self
3
3
 
4
4
  def gem_version
5
- "0.1.8"
5
+ "0.1.9"
6
6
  end
7
7
 
8
8
  def ascii_art
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Layne Faler
@@ -66,6 +66,7 @@ files:
66
66
  - lib/autogenerators/bash_commands/install_rspec.sh
67
67
  - lib/autogenerators/generator_templates/application_record.txt
68
68
  - lib/autogenerators/generator_templates/controller.txt
69
+ - lib/autogenerators/generator_templates/policy.txt
69
70
  - lib/autogenerators/generator_templates/test_rspec_controller.txt
70
71
  - lib/autogenerators/generator_templates/test_seeder.txt
71
72
  - lib/autogenerators/handlers/controller.rb