gearhead 0.3.0 → 0.4.0

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: afb6a1e6b19a280a9d989f0ce075b8388efe9ddf6a33625fdd7fec0fcf8d06e0
4
- data.tar.gz: 9b3eb8f0bef7c65e4c4753a34112832948510138ee6cb10fbcb62a7fc4135f1d
3
+ metadata.gz: 514fd5af0293e62efdbb83d18eda79c72412f06ab60ab96adcb19d48bdc3fd82
4
+ data.tar.gz: 4350999d8e8194ca68726b5893a5c32d8d7de43aeb14fba93b3e7f14a2806666
5
5
  SHA512:
6
- metadata.gz: ff6f8c1df2067283d63f3056cbc51dfe7d5793474e3861e1c2d043f00ec44d01f1c6736bb65a990cc8b159fbc3caee0b1d9fdeda8b190271dbc3257fa6c551e9
7
- data.tar.gz: ff94d8200b2589893b7f7122f196438a54211dc77dc8c40319c172ed3d7f67b9edc37e9c4651d6a0f9081cc72da0338b72dcb31da3608cf58271c1474fe69424
6
+ metadata.gz: c6587358c938a6c2538adff9f53b88055cf7cfa79b128d0c4268712a3ddff4953f35b0b163437c543585054dd97a3cdffd09185ed92c96dc1d4b83ee873b7dcc
7
+ data.tar.gz: ecf7fc77d8c0b6d23e2a26e602666ebdffa22bfceeebc9570691ea2b1414eaa96ff58986036b5fb0a09210106554b30b4f7c26693751cf2d12dc5acc584a449c
@@ -7,9 +7,16 @@ module Gearhead
7
7
  end
8
8
 
9
9
  def apply
10
+ if Gearhead.config.automount.enabled?
11
+ define_automount_route
12
+ end
10
13
  define_gear_routes
11
14
  end
12
15
 
16
+ def define_automount_route
17
+ @router.resources :gears, path: [::Gearhead.config.endpoint, ":resource_class"].join("/"), controller: "gearhead/gears", param: :resource_id
18
+ end
19
+
13
20
  def define_gear_routes
14
21
  ::Gearhead.registry.all.each do |thing|
15
22
  @router.resources thing.resource.model_name.route_key, path: [::Gearhead.config.endpoint, thing.path].join("/"), controller: "gearhead/gears", param: :resource_id, defaults: { resource_class: thing.resource.model_name.route_key } do
@@ -0,0 +1,15 @@
1
+ module Gearhead
2
+ module Utils
3
+ module_function
4
+
5
+ def check_endpoint!(endpoint)
6
+ return if endpoint.start_with?("/") && !endpoint.end_with?("/")
7
+ unless endpoint.start_with?("/")
8
+ raise ArgumentError, "Endpoint must start with /. Endpoint is: `#{endpoint}'"
9
+ end
10
+ if endpoint.end_with?("/")
11
+ raise ArgumentError, "Endpoint must not end with /. Endpoint is: `#{endpoint}'"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Gearhead
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -5,12 +5,19 @@ module Gearhead
5
5
 
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
+ class_option :automount, default: false, desc: "Enable automounting (default is false)"
9
+ class_option :endpoint, default: "/gearhead", desc: "The route to mount Gearhead on (default is /gearhead)"
10
+
8
11
  def generate_config_file
12
+ @automount = options[:automount]
13
+ @endpoint = options[:endpoint]
14
+ Gearhead::Utils.check_endpoint!(@endpoint)
15
+
9
16
  template "gearhead.rb.erb", "config/initializers/gearhead.rb"
10
17
  end
11
18
 
12
19
  def install_routes
13
- inject_into_file "config/routes.rb", "\n Gearbox.routes(self)", after: /Rails.application.routes.draw do/
20
+ inject_into_file "config/routes.rb", "\n Gearhead.routes(self)", after: /Rails.application.routes.draw do/
14
21
  end
15
22
  end
16
23
  end
@@ -3,7 +3,7 @@ Gearhead.setup do |config|
3
3
  #
4
4
  # The endpoint in which to mount gearhead on.
5
5
  # Default is "/gearhead" — must start with a slash, and have no trailing slash
6
- # config.endpoint = "/api/v314"
6
+ <% if [nil, ""].include?(@endpoint) %># config.endpoint = "/api/v314"<%else %>config.endpoint = "<%= @endpoint %>"<% end %>
7
7
  #
8
8
  # The default actions a Gear can respond to
9
9
  # Default is [:index, :create, :show, :update, :destroy]
@@ -27,7 +27,7 @@ Gearhead.setup do |config|
27
27
  # == Automount
28
28
  #
29
29
  # Change this to true if you want to automatically mount all your resources.
30
- # config.automount.enabled = false
30
+ <% if [nil, "", false].include?(@automount) %># config.automount.enabled = false<%else %>config.automount.enabled = true<% end %>
31
31
  #
32
32
  # Automatically mount most of your resources
33
33
  # config.automount.resources = ['User', 'Post', 'Comment']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gearhead
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh
@@ -235,6 +235,7 @@ files:
235
235
  - lib/gearhead/serializers/invalid_request_serializer.rb
236
236
  - lib/gearhead/serializers/invalid_resource_serializer.rb
237
237
  - lib/gearhead/serializers/lookup.rb
238
+ - lib/gearhead/utils.rb
238
239
  - lib/gearhead/version.rb
239
240
  - lib/generators/gearhead/gear/gear_generator.rb
240
241
  - lib/generators/gearhead/gear/templates/gear.rb.erb