Class: Rang::Api::Generators::ConfigureGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/rang/api/configure/configure_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_active_model_serializers_to_gemfileObject



12
13
14
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 12

def add_active_model_serializers_to_gemfile
  gem "active_model_serializers", "~> 0.9.0"
end

#add_ams_initializerObject



20
21
22
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 20

def add_ams_initializer
  template "active_model_serializer.rb", "config/initializers/active_model_serializer.rb"
end

#add_angular_restmod_to_gemfileObject



8
9
10
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 8

def add_angular_restmod_to_gemfile
  generate "rang:bower:add", "angular-restmod '~> 0.16' quiet"
end

#add_controller_api_namespaceObject



28
29
30
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 28

def add_controller_api_namespace
  empty_directory "app/controllers/api"
end

#add_example_serializerObject



32
33
34
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 32

def add_example_serializer
  generate "serializer", "example title:string body:string"
end

#add_route_api_scopeObject



24
25
26
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 24

def add_route_api_scope
  route "scope 'api(/:version)', :module => :api, :version => /v\d+?/, :defaults => {format: :json} do\n    # API routes go here\n  end\n"
end

#add_to_application_jsObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 36

def add_to_application_js
  application_js_path = Rails.application.assets.find_asset("application.js").pathname.to_s

  if !no? "\n\nAdd angular-restmod to application.js? [Yn]", :cyan
    inject_into_file application_js_path, after: /^\/\/= require angular$/ do
      "\n//= require angular-restmod/angular-restmod-bundle"
    end
  end
rescue
  say "Application.js not found, not adding require for angular-restmod.", :red
end

#bundle_installObject



16
17
18
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 16

def bundle_install
  bundle!
end

#inform_of_actionsObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rails/generators/rang/api/configure/configure_generator.rb', line 48

def inform_of_actions
  say "\n\n      ******      \n\n"
  say "\nAPI Configured, using:\n\n", :green
  say "## Active_model_serializers", :bold
  say "An example serializer has been written in app/serializers/example_serializer.rb", :cyan
  say "You can (and should) read the full docs here: https://github.com/rails-api/active_model_serializers/tree/0-9-stable\n\n", :cyan
  say "## Angular-restmod", :bold
  say "A Rails-inspired ORM for Angular.", :cyan
  say "Full docs here: https://github.com/platanus/angular-restmod", :cyan
  say "You will need to include 'restmod' in the angular.module calls where you want to use it.\n\n", :cyan
end