phlex-rails 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ef3316773401cb9a664f24dfaf751f282bdceafc22db5d5aa59173d96b0794c
4
- data.tar.gz: 253849ceeeb4af1c1a3dd673c6e862cb17f8b1c3a13695556ccfc5b8d2855ce0
3
+ metadata.gz: 28ff15970d3e9f51641fcf4739a1ce10cf7d026a3e11bacf88892372a5aa8180
4
+ data.tar.gz: dcd2019092caec7c33a8fb837396d072b2894e13819074423c679a6555809f47
5
5
  SHA512:
6
- metadata.gz: 5e3cedfb00ab5762f2ffeeecf66e59a28dd8eac55d44272521c3c4094f0bd66d41d6a64925242cf429678417e87c536d644b3da0ebc0a566900665fb8863e894
7
- data.tar.gz: a88ea4826134ece2cda7cfae473e362dc1571822a4e27865e99b695bbdcf5bf2cd4d745334d6a1927a10cd463c7ccac54244af99d7255be6b28a144b5f6020e3
6
+ metadata.gz: f60d2e3e17bafb9d40ac0e7287346cd97146954e2a3901e45c82d5d937bea4eb9468d7d573bceff4043a7244834426a0cf8c35065027582901534c68e9e8911d
7
+ data.tar.gz: 6b4141a6ffc3a44c294370ba17cf15a8e9d683e6beeae00fd1b7045f842820155d1c8de8e396892f991af4eec5ca5759012ca606009213dc30bdf727669ed9ab
@@ -5,9 +5,19 @@ module Phlex
5
5
  class ControllerGenerator < ::Rails::Generators::NamedBase # :nodoc:
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
- argument :actions, type: :array, default: [], banner: "action action"
9
- class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
10
- class_option :parent, type: :string, default: "ApplicationController", desc: "The parent class for the generated controller"
8
+ argument :actions,
9
+ type: :array,
10
+ default: [],
11
+ banner: "action action"
12
+
13
+ class_option :skip_routes,
14
+ type: :boolean,
15
+ desc: "Don't add routes to config/routes.rb."
16
+
17
+ class_option :parent,
18
+ type: :string,
19
+ default: "ApplicationController",
20
+ desc: "The parent class for the generated controller"
11
21
 
12
22
  check_class_collision suffix: "Controller"
13
23
 
@@ -20,15 +30,19 @@ module Phlex
20
30
  empty_directory base_path
21
31
 
22
32
  actions.each do |action|
23
- Rails::Generators.invoke("phlex:view", [remove_possible_suffix(name) + "/" + action])
33
+ ::Rails::Generators.invoke("phlex:page", [name + "/" + action])
24
34
  end
25
35
  end
26
36
 
27
37
  def add_routes
28
38
  return if options[:skip_routes]
29
- return if actions.empty?
30
39
 
31
- routing_code = actions.map { |action| "get '#{file_name}/#{action}'" }.join("\n")
40
+ routing_code = "resources :#{file_name}"
41
+
42
+ if actions.any?
43
+ routing_code << ", only: [#{actions.map { ":#{_1}" }.join(', ')}]"
44
+ end
45
+
32
46
  route routing_code, namespace: regular_class_path
33
47
  end
34
48
 
@@ -43,7 +57,11 @@ module Phlex
43
57
  end
44
58
 
45
59
  def file_name
46
- @_file_name ||= remove_possible_suffix(super)
60
+ remove_possible_suffix(super)
61
+ end
62
+
63
+ def name
64
+ remove_possible_suffix(super)
47
65
  end
48
66
 
49
67
  def remove_possible_suffix(name)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper