comment_box 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 16f1e8c95e3a5e09d10cbffaf069baae1727eeda
4
- data.tar.gz: f8a6a3e08a0e61502c9b3028d5628744abc104ca
3
+ metadata.gz: 03804456d9b8cfcdf5d5571a0fde107f2e561c0b
4
+ data.tar.gz: fb6f291e13dbbff80a722485623d1eaf0de53c2d
5
5
  SHA512:
6
- metadata.gz: 8359905afdb14bae8e220d81b58ad0e1f59ca1ab7056cebb3222ea4cab8da64e50adb1258437b9751bfd82f2d196a2814886d82de8615fdf36877ff287e71478
7
- data.tar.gz: b3fe9b6fadff58b736416c8cdd1fb8d5a8473670ee50c86f96d52c72fb62d18a8461f5dea5d87355b357a979812e1b335437918f60e98d62fb3c7cd931f01e94
6
+ metadata.gz: ae3181940ca4925df6112f4568de8269c4ff23587d56f58fba8f7c6334f77bf5f68d7f6479f339336fbefd934251e224ad04afde0640020f9c7f0bc4e3c81fe0
7
+ data.tar.gz: f840751c726b37a6dac8b023b821d5e6fbbb7ce45332eb0c89aff5acd6ba55866a59f3affe96b76f70d5e41e2232764089f9c230503d3b16dd6c538357d2ea39
@@ -1,3 +1,3 @@
1
1
  module CommentBox
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -6,7 +6,7 @@ module ActiveRecord
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
 
8
8
  def copy_comment_box_migration
9
- migration_template 'migration.rb', 'db/migrate/comment_box_create_comments.rb'
9
+ migration_template 'migration.rb', "db/migrate/comment_box_create_#{table_name}.rb"
10
10
  end
11
11
  end
12
12
  end
@@ -1,6 +1,6 @@
1
- class CommentBoxCreateComment < ActiveRecord::Migration
1
+ class CommentBoxCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
2
  def up
3
- create_table :comments do |t|
3
+ create_table :<%= table_name %> do |t|
4
4
  t.string :author
5
5
  t.text :text
6
6
  t.string :likes
@@ -10,6 +10,6 @@ class CommentBoxCreateComment < ActiveRecord::Migration
10
10
  end
11
11
 
12
12
  def down
13
- drop_table :comments
13
+ drop_table :<%= table_name %>
14
14
  end
15
15
  end
@@ -0,0 +1,35 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module CommentBox
4
+ module Generators
5
+ class CommentBoxGenerator < Rails::Generators::NamedBase
6
+ include Rails::Generators::ResourceHelpers
7
+ source_root File.expand_path('../../templates', __FILE__)
8
+
9
+ namespace 'comment_box'
10
+ hook_for :orm, required: true
11
+
12
+ desc 'Generate migration file for comments box'
13
+
14
+ def copy_comment_box_model
15
+ template 'models/cb_model.rb', model_path
16
+ end
17
+
18
+ def copy_comment_box_controller
19
+ template 'controllers/cb_controller.rb', controller_path
20
+ end
21
+
22
+ def add_comment_box_routes
23
+ route "resources :#{table_name}, except: [:new, :edit]"
24
+ end
25
+
26
+ def model_path
27
+ File.join('app', 'models', "#{file_path}.rb")
28
+ end
29
+
30
+ def controller_path
31
+ File.join('app', 'controllers', "#{table_name}_controller.rb")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,44 @@
1
+ class <%= table_name.capitalize %>Controller < ApplicationController
2
+ before_action :fetch_<%= singular_name %>, only: [:show, :update, :destroy]
3
+
4
+ def index
5
+ render json: <%= class_name %>.order(updated_at: 'desc')
6
+ end
7
+
8
+ def show
9
+ render json: fetch_<%= singular_name %>
10
+ end
11
+
12
+ def create
13
+ <%= singular_name %> = <%= class_name %>.new(<%= singular_name %>_params)
14
+
15
+ if <%= singular_name %>.save
16
+ render json: {message: '<%= class_name %> created!'}, status: :created
17
+ else
18
+ render json: {message: 'An error occurred.'}, status: :bad_request
19
+ end
20
+ end
21
+
22
+ def update
23
+ if fetch_<%= singular_name %>.update(<%= singular_name %>_params)
24
+ render json: {message: '<%= class_name %> updated!'}, status: :accepted
25
+ else
26
+ render json: {message: 'Update failed'}, status: :bad_request
27
+ end
28
+ end
29
+
30
+ def destroy
31
+ fetch_<%= singular_name %>.destroy
32
+ render json: {message: '<%= class_name %> deleted!'}, status: :no_content
33
+ end
34
+
35
+ private
36
+
37
+ def fetch_<%= singular_name %>
38
+ <%= class_name %>.find_by(id: params[:id])
39
+ end
40
+
41
+ def <%= singular_name %>_params
42
+ params.require(:<%= singular_name %>).permit(:author, :text, :likes)
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ validates_presence_of :author, :text
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comment_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fiyin Adebayo
@@ -9,7 +9,49 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-07-13 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: spring
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
13
55
  description: Provides robust comment functionality for any application.
14
56
  email: fiyinsimeon@gmail.com
15
57
  executables: []
@@ -20,7 +62,10 @@ files:
20
62
  - lib/comment_box/version.rb
21
63
  - lib/generators/active_record/comment_box_generator.rb
22
64
  - lib/generators/active_record/templates/migration.rb
23
- homepage:
65
+ - lib/generators/comment_box/comment_box_generator.rb
66
+ - lib/generators/templates/controllers/cb_controller.rb
67
+ - lib/generators/templates/models/cb_model.rb
68
+ homepage: ''
24
69
  licenses:
25
70
  - MIT
26
71
  metadata: {}
@@ -32,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
77
  requirements:
33
78
  - - ">="
34
79
  - !ruby/object:Gem::Version
35
- version: '0'
80
+ version: 2.3.1
36
81
  required_rubygems_version: !ruby/object:Gem::Requirement
37
82
  requirements:
38
83
  - - ">="