crud 0.0.4 → 0.1.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
- SHA1:
3
- metadata.gz: c13137f3cd61c4548411788c62812424776b992b
4
- data.tar.gz: 170567c4d0ae6a5a5f8a9c91634ab0be6a7e2c3d
2
+ SHA256:
3
+ metadata.gz: c72cddfbc0bacb84368d337f7fae090ec6a90cfb1426551dc627adecab354b58
4
+ data.tar.gz: 747abf05a99d8295c8a4ffc34904c5b3f97b2b1f076d72b347f36dc487843e3a
5
5
  SHA512:
6
- metadata.gz: 9ce6de70b3b1ccf93869be5a7e8969a8d3dc4c049f9288c62a13c14638657f65c226dfc83993590599cae500e458287f7cf5e1cff799a1766cea1994cf2ac301
7
- data.tar.gz: aa2ca0f928033540a88d1a639ce78b407cf2b4535827c9c63dcba36bce787acca965970d87e02b5482820cf29f147e074e95cb5f04e58c4c472aea56fb5ec930
6
+ metadata.gz: 40bb0c99d245f7d44ffb7b290b915deffc792270df46864af6afea5ba412c3e0647ae05a0dd695a57f9debd29f159b2450e3601c8e5afac96d27a23a2a7d8cd7
7
+ data.tar.gz: f99011fdc613bd7746717fcddb61b7ed483fea668e28fa9dfca88c4c7f226e483c370558b3967ce8471d2106e9c12d616a5561005c1a33c55e3ba9d1fe91818c
data/Rakefile CHANGED
@@ -54,7 +54,7 @@ task :cucumber => 'app:cucumber'
54
54
 
55
55
  # ci_reporter tasks
56
56
  require 'rubygems'
57
- require 'ci/reporter/rake/test_unit' # use this if you’re using Test::Unit
57
+ #require 'ci/reporter/rake/test_unit' # use this if you’re using Test::Unit
58
58
  require 'ci/reporter/rake/rspec' # use this if you’re using RSpec
59
59
  require 'ci/reporter/rake/cucumber' # use this if you're using Cucumber
60
60
 
@@ -0,0 +1,5 @@
1
+ module Crud
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -2,12 +2,22 @@ require_dependency "crud/crud_base_controller"
2
2
 
3
3
  module Crud
4
4
  class CrudController < CrudBaseController
5
- around_filter :catch_not_found
6
5
 
7
- before_filter :is_allowed_to_view?, :only => [:index, :show]
8
- before_filter :is_allowed_to_update?, :only => [:new, :create, :edit, :update, :destroy, :delete]
9
- before_filter :get_klass_info_from_params
10
- before_filter :get_visible_attributes
6
+ if Rails.version.to_f >= 5.1
7
+ around_action :catch_not_found
8
+
9
+ before_action :get_klass_data, :only => [:show, :edit, :update, :destroy, :delete]
10
+ before_action :get_klass_info_from_params
11
+ before_action :get_visible_attributes
12
+ else
13
+ around_filter :catch_not_found
14
+
15
+ before_filter :is_allowed_to_view?, :only => [:index, :show]
16
+ before_filter :is_allowed_to_update?, :only => [:new, :create, :edit, :update, :destroy, :delete]
17
+ before_filter :get_klass_data, :only => [:show, :edit, :update, :destroy, :delete]
18
+ before_filter :get_klass_info_from_params
19
+ before_filter :get_visible_attributes
20
+ end
11
21
 
12
22
  # GET
13
23
  def index
@@ -43,8 +53,6 @@ module Crud
43
53
 
44
54
  # GET
45
55
  def show
46
- @klass_data = @klass_info[:class].find(params[:id])
47
-
48
56
  respond_to do |format|
49
57
  format.html # index.html.erb
50
58
  format.json { render :json => @klass_data }
@@ -65,12 +73,11 @@ module Crud
65
73
 
66
74
  # GET
67
75
  def edit
68
- @klass_data = @klass_info[:class].find(params[:id])
69
76
  end
70
77
 
71
78
  # POST
72
79
  def create
73
- @klass_data = @klass_info[:class].new(params[@klass_info[:name_as_sym]])
80
+ @klass_data = @klass_info[:class].new(klass_params)
74
81
 
75
82
  respond_to do |format|
76
83
  if @klass_data.save
@@ -87,10 +94,8 @@ module Crud
87
94
 
88
95
  # PUT
89
96
  def update
90
- @klass_data = @klass_info[:class].find(params[:id])
91
-
92
97
  respond_to do |format|
93
- if @klass_data.update_attributes(params[@klass_info[:name_as_sym]])
98
+ if @klass_data.update_attributes(klass_params)
94
99
  format.html { redirect_to show_path(:class_name => @klass_info[:name], :id => @klass_data.id), :notice => "#{@klass_info[:name]} was successfully updated" }
95
100
  format.json { head :no_content }
96
101
  format.xml { head :ok }
@@ -104,7 +109,6 @@ module Crud
104
109
 
105
110
  # DELETE
106
111
  def delete
107
- @klass_data = @klass_info[:class].find(params[:id])
108
112
  @klass_data.delete
109
113
 
110
114
  respond_to do |format|
@@ -116,7 +120,6 @@ module Crud
116
120
 
117
121
  # DELETE
118
122
  def destroy
119
- @klass_data = @klass_info[:class].find(params[:id])
120
123
  @klass_data.destroy
121
124
 
122
125
  respond_to do |format|
@@ -126,7 +129,24 @@ module Crud
126
129
  end
127
130
  end
128
131
 
129
- private
132
+ private
133
+ # Use callbacks to share common setup or constraints between actions.
134
+ def get_klass_data
135
+ @klass_info = get_klass_info_from_params
136
+ @klass_data = @klass_info[:class].find(params[:id])
137
+ end
138
+
139
+ # Never trust parameters from the scary internet, only allow the white list through.
140
+ def klass_params
141
+ visible_attributes = Array.new
142
+ get_visible_attributes.each do |attribute|
143
+ visible_attributes << attribute[:column_name].to_sym
144
+ end
145
+ params.fetch(@klass_info[:name_as_sym], visible_attributes)
146
+
147
+ # Allow all visible attributes to be written to (bypass mass-assignment protection)
148
+ params.require(@klass_info[:name_as_sym]).permit(visible_attributes)
149
+ end
130
150
 
131
151
  def get_klass_info_from_params
132
152
  if params[:class_name]
@@ -2,8 +2,13 @@ require_dependency "crud/crud_base_controller"
2
2
 
3
3
  module Crud
4
4
  class DashboardController < CrudBaseController
5
- before_filter :is_allowed_to_view?, :only => [:index]
6
- before_filter :get_klass_list
5
+
6
+ if Rails.version.to_f >= 5.1
7
+ before_action :get_klass_list
8
+ else
9
+ before_filter :is_allowed_to_view?, :only => [:index]
10
+ before_filter :get_klass_list
11
+ end
7
12
 
8
13
  def index
9
14
  end
@@ -0,0 +1,4 @@
1
+ module Crud
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Crud
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Crud
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Crud
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -30,16 +30,17 @@ module Crud
30
30
  private
31
31
 
32
32
  def create_klasses_from_model_names(model_names)
33
- model_names.inject([]) do |output, model_name|
34
- klass_name = model_name
33
+ output = Array.new
34
+ klass_names = model_names.select {|model_name| (model_name.constantize.is_a? Class) && !(model_name == 'ApplicationRecord')}
35
+ klass_names.each do |klass_name|
35
36
  begin
36
- klass = klass_name.constantize
37
- output << "::#{klass}".constantize if klass_name == klass.to_s
37
+ klass = Object.const_get(klass_name)
38
+ output << klass if klass_name == klass.to_s
38
39
  rescue Exception => e
39
40
  Rails.logger.debug e.message
40
41
  end
41
- output
42
42
  end
43
+ output
43
44
  end
44
45
 
45
46
  def remove_klasses_without_table(klasses)
@@ -1,5 +1,13 @@
1
1
  <%= render 'error_messages', :model => @klass_data %>
2
2
 
3
+ <% if is_allowed_to_update? %>
4
+ <%= link_to 'Edit', edit_path(:class_name => @klass_info[:name], :id => @klass_data.id) %> |
5
+ <% end %>
6
+ <%= link_to "Back (List all #{@klass_info[:name].pluralize})", index_path(:class_name => @klass_info[:name]) %>
7
+
8
+ <br/>
9
+ <br/>
10
+
3
11
  <% @visible_attributes.each do |attribute| %>
4
12
  <p>
5
13
  <b><%= label(@klass_info[:name].to_sym, attribute[:column_name].to_sym) %>:</b>
@@ -0,0 +1,8 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>/* Email styles need to be inline */</style>
6
+ </head>
7
+ <body><%= yield %></body>
8
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ Rails.application.config.assets.precompile += %w( crud/dashboard.css crud/dashboard.js )
2
+ Rails.application.config.assets.precompile += %w( crud/pagination.css crud/pagination.js )
3
+ Rails.application.config.assets.precompile += %w( crud/search-icon.png )
@@ -7,7 +7,7 @@ require "crud/version"
7
7
  # Describe your gem and declare its dependencies:
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "crud"
10
- s.version = Crud::VERSION.dup
10
+ s.version = Crud::VERSION::STRING.dup
11
11
  s.authors = ["Everard Brown"]
12
12
  s.email = ["Everard.Brown@htcl.eu"]
13
13
  s.homepage = "https://github.com/htcl/crud"
@@ -22,8 +22,10 @@ Gem::Specification.new do |s|
22
22
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "crud", "--main", "README.md"]
23
23
  s.extra_rdoc_files = ["CHANGELOG", "README.md", "lib/tasks/crud_tasks.rake", "lib/crud.rb"]
24
24
 
25
- s.add_dependency 'rails'
25
+ s.add_dependency 'rails', '~> 5.0'
26
26
  s.add_dependency 'jquery-rails'
27
27
  s.add_dependency 'jquery-ui-rails'
28
28
  s.add_dependency 'will_paginate'
29
+
30
+ #s.add_development_dependency 'sqlite3'
29
31
  end
@@ -1,3 +1,5 @@
1
+ require 'rails'
2
+
1
3
  module Crud
2
4
  class Engine < ::Rails::Engine
3
5
  isolate_namespace Crud
@@ -11,10 +13,10 @@ module Crud
11
13
  #config.autoload_paths << File.expand_path("../validators", __FILE__)
12
14
 
13
15
  config.generators do |g|
14
- g.test_framework :rspec, :fixture_replacement => :factory_girl, :views => false, :helper => true
16
+ g.test_framework :rspec, :fixture_replacement => :factory_bot, :views => false, :helper => true
15
17
  g.view_specs false
16
18
  g.helper_specs true
17
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
19
+ g.fixture_replacement :factory_bot, :dir => 'spec/factories'
18
20
  end
19
21
 
20
22
  # Load translations from config/locales/*.rb,yml are auto loaded.
@@ -1,3 +1,19 @@
1
1
  module Crud
2
- VERSION = "0.0.4"
2
+ # Returns the version of the currently loaded gem as a <tt>Gem::Version</tt>
3
+ def self.gem_version
4
+ Gem::Version.new VERSION::STRING
5
+ end
6
+
7
+ def self.version
8
+ VERSION::STRING.to_f
9
+ end
10
+
11
+ module VERSION
12
+ MAJOR = 0
13
+ MINOR = 1
14
+ PATCH = 0
15
+ PRE = nil
16
+
17
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
18
+ end
3
19
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Everard Brown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2018-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jquery-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jquery-ui-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: will_paginate
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Performs CRUD operations by reflection
@@ -90,11 +90,16 @@ files:
90
90
  - app/assets/stylesheets/crud/flash_notices.css
91
91
  - app/assets/stylesheets/crud/pagination.css
92
92
  - app/assets/stylesheets/dataTables/jquery.dataTables-override.css
93
+ - app/controllers/crud/application_controller.rb
93
94
  - app/controllers/crud/crud_base_controller.rb
94
95
  - app/controllers/crud/crud_controller.rb
95
96
  - app/controllers/crud/dashboard_controller.rb
97
+ - app/helpers/crud/application_helper.rb
96
98
  - app/helpers/crud/crud_helper.rb
97
99
  - app/helpers/crud/dashboard_helper.rb
100
+ - app/jobs/crud/application_job.rb
101
+ - app/mailers/crud/application_mailer.rb
102
+ - app/models/crud/application_record.rb
98
103
  - app/models/crud/klass_info.rb
99
104
  - app/models/crud/klass_list.rb
100
105
  - app/models/crud/menus/development_menu.rb
@@ -110,7 +115,10 @@ files:
110
115
  - app/views/crud/crud/show.html.erb
111
116
  - app/views/crud/dashboard/index.html.erb
112
117
  - app/views/layouts/crud/application.html.erb
118
+ - app/views/layouts/crud/mailer.html.erb
119
+ - app/views/layouts/crud/mailer.text.erb
113
120
  - config/cucumber.yml
121
+ - config/initializers/assets.rb
114
122
  - config/initializers/inflections.rb
115
123
  - config/initializers/rails_engine.rb
116
124
  - config/initializers/will_paginate.rb
@@ -130,28 +138,28 @@ licenses:
130
138
  metadata: {}
131
139
  post_install_message:
132
140
  rdoc_options:
133
- - --line-numbers
134
- - --inline-source
135
- - --title
141
+ - "--line-numbers"
142
+ - "--inline-source"
143
+ - "--title"
136
144
  - crud
137
- - --main
145
+ - "--main"
138
146
  - README.md
139
147
  require_paths:
140
148
  - lib
141
149
  required_ruby_version: !ruby/object:Gem::Requirement
142
150
  requirements:
143
- - - '>='
151
+ - - ">="
144
152
  - !ruby/object:Gem::Version
145
153
  version: '0'
146
154
  required_rubygems_version: !ruby/object:Gem::Requirement
147
155
  requirements:
148
- - - '>='
156
+ - - ">="
149
157
  - !ruby/object:Gem::Version
150
158
  version: '0'
151
159
  requirements: []
152
160
  rubyforge_project:
153
- rubygems_version: 2.4.7
161
+ rubygems_version: 2.7.4
154
162
  signing_key:
155
163
  specification_version: 4
156
- summary: Crud engine (v0.0.4)
164
+ summary: Crud engine (v0.1.0)
157
165
  test_files: []