mvc_one 0.1.0.pre.rc3 → 0.1.0.pre.rc5

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: 79e730b79796e5e4db6eafa6f600b2efd052e6e2c910fd1f493408ce62ce56ae
4
- data.tar.gz: cacdd0774c86899f69c2c60f918d16c562b350283f2cfd6f46f23cce5aebf3d8
3
+ metadata.gz: 69e5e06df9043af06f3c3cad8f62755e91a772a2b894726f7a5f49edb566ae60
4
+ data.tar.gz: 984bfbd6a6428678c6096e300cc0a0c161f80ccf01a04eeb6d259020c25178b5
5
5
  SHA512:
6
- metadata.gz: 39401230ffb11978a78759226b30b7ec203db0b3cf66649b7b5bd9b2d1bce77eee6aa8f99c1b9b1610853cf573b10e5f9a849bc649459524d048bf715c11ecb9
7
- data.tar.gz: d1eed2a7a4ea87b4bd402066bd6734f971a5284acb722f35671aaf3b447b0c7398e7d32823bac9ba6ff2ffb4bc066a3b3d2839abf7fb8e96acf8434a5d85ae29
6
+ metadata.gz: 864f1663d0f62f71dcaa7cdc46dd6adff1b67bec0ff5a7b0530bac44e149b4207dd252936a0b7194e4371b457457c65a616bb352fad6c4247eeeac543555f582
7
+ data.tar.gz: 7902064cb8b39c02722285d7692fc1c6a588fac5039bd1af54d6789bc0827629892cd1b410c1e536537b7926e6c5ba743415317231291dbc174f39c20cf6b4bf
data/.rubocop.yml CHANGED
@@ -1,13 +1,36 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-sequel
4
+ - rubocop-rspec
5
+
1
6
  AllCops:
2
- TargetRubyVersion: 2.6
7
+ NewCops: enable
8
+
9
+ Metrics/BlockLength:
10
+ Enabled: false
11
+
12
+ RSpec/MultipleExpectations:
13
+ Enabled: false
14
+
15
+ RSpec/ExampleLength:
16
+ Enabled: false
17
+
18
+ RSpec/MultipleMemoizedHelpers:
19
+ Enabled: false
20
+
21
+ Metrics/AbcSize:
22
+ Max: 50
23
+
24
+ Metrics/ClassLength:
25
+ Max: 150
3
26
 
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
27
+ Metrics/MethodLength:
28
+ Enabled: false
7
29
 
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
30
+ Style/Documentation:
31
+ Enabled: false
11
32
 
12
- Layout/LineLength:
13
- Max: 120
33
+ Naming/PredicateName:
34
+ AllowedMethods:
35
+ - 'has_many'
36
+ - 'has_one'
data/Gemfile CHANGED
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in mvc_one.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
11
-
12
- gem "rubocop", "~> 1.21"
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rubocop', require: false
11
+ gem 'rubocop-rake', require: false
12
+ gem 'rubocop-rspec', require: false
13
+ gem 'rubocop-sequel', require: false
data/Gemfile.lock CHANGED
@@ -1,18 +1,84 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mvc_one (0.1.0.pre.rc1)
5
- thor
4
+ mvc_one (0.1.0.pre.rc5)
5
+ bcrypt (~> 3.1)
6
+ dry-struct (~> 1.5)
7
+ dry-transaction (~> 0.14)
8
+ dry-validation (~> 1.9)
9
+ rack (~> 3)
10
+ rack-session (~> 2)
11
+ sequel (~> 5.60)
12
+ slim (~> 5)
13
+ sqlite3 (~> 1.5)
14
+ thor (~> 1.2)
6
15
 
7
16
  GEM
8
17
  remote: https://rubygems.org/
9
18
  specs:
10
19
  ast (2.4.2)
20
+ bcrypt (3.1.18)
21
+ concurrent-ruby (1.2.2)
11
22
  diff-lcs (1.5.0)
23
+ dry-configurable (1.0.1)
24
+ dry-core (~> 1.0, < 2)
25
+ zeitwerk (~> 2.6)
26
+ dry-core (1.0.0)
27
+ concurrent-ruby (~> 1.0)
28
+ zeitwerk (~> 2.6)
29
+ dry-events (1.0.1)
30
+ concurrent-ruby (~> 1.0)
31
+ dry-core (~> 1.0, < 2)
32
+ dry-inflector (1.0.0)
33
+ dry-initializer (3.1.1)
34
+ dry-logic (1.5.0)
35
+ concurrent-ruby (~> 1.0)
36
+ dry-core (~> 1.0, < 2)
37
+ zeitwerk (~> 2.6)
38
+ dry-matcher (0.10.0)
39
+ dry-core (~> 1.0)
40
+ dry-monads (1.6.0)
41
+ concurrent-ruby (~> 1.0)
42
+ dry-core (~> 1.0, < 2)
43
+ zeitwerk (~> 2.6)
44
+ dry-schema (1.13.0)
45
+ concurrent-ruby (~> 1.0)
46
+ dry-configurable (~> 1.0, >= 1.0.1)
47
+ dry-core (~> 1.0, < 2)
48
+ dry-initializer (~> 3.0)
49
+ dry-logic (>= 1.5, < 2)
50
+ dry-types (>= 1.7, < 2)
51
+ zeitwerk (~> 2.6)
52
+ dry-struct (1.6.0)
53
+ dry-core (~> 1.0, < 2)
54
+ dry-types (>= 1.7, < 2)
55
+ ice_nine (~> 0.11)
56
+ zeitwerk (~> 2.6)
57
+ dry-transaction (0.15.0)
58
+ dry-core (~> 1.0)
59
+ dry-events (~> 1.0)
60
+ dry-matcher (~> 0.10)
61
+ dry-monads (~> 1.6)
62
+ dry-types (1.7.1)
63
+ concurrent-ruby (~> 1.0)
64
+ dry-core (~> 1.0)
65
+ dry-inflector (~> 1.0)
66
+ dry-logic (~> 1.4)
67
+ zeitwerk (~> 2.6)
68
+ dry-validation (1.10.0)
69
+ concurrent-ruby (~> 1.0)
70
+ dry-core (~> 1.0, < 2)
71
+ dry-initializer (~> 3.0)
72
+ dry-schema (>= 1.12, < 2)
73
+ zeitwerk (~> 2.6)
74
+ ice_nine (0.11.2)
12
75
  json (2.6.3)
13
76
  parallel (1.22.1)
14
77
  parser (3.2.1.0)
15
78
  ast (~> 2.4.1)
79
+ rack (3.0.4.2)
80
+ rack-session (2.0.0)
81
+ rack (>= 3.0.0)
16
82
  rainbow (3.1.1)
17
83
  rake (13.0.6)
18
84
  regexp_parser (2.7.0)
@@ -42,9 +108,26 @@ GEM
42
108
  unicode-display_width (>= 2.4.0, < 3.0)
43
109
  rubocop-ast (1.26.0)
44
110
  parser (>= 3.2.1.0)
111
+ rubocop-capybara (2.17.1)
112
+ rubocop (~> 1.41)
113
+ rubocop-rake (0.6.0)
114
+ rubocop (~> 1.0)
115
+ rubocop-rspec (2.18.1)
116
+ rubocop (~> 1.33)
117
+ rubocop-capybara (~> 2.17)
118
+ rubocop-sequel (0.3.4)
119
+ rubocop (~> 1.0)
45
120
  ruby-progressbar (1.11.0)
121
+ sequel (5.66.0)
122
+ slim (5.0.0)
123
+ temple (~> 0.10.0)
124
+ tilt (>= 2.0.6, < 2.1)
125
+ sqlite3 (1.6.1-x86_64-darwin)
126
+ temple (0.10.0)
46
127
  thor (1.2.1)
128
+ tilt (2.0.11)
47
129
  unicode-display_width (2.4.2)
130
+ zeitwerk (2.6.7)
48
131
 
49
132
  PLATFORMS
50
133
  x86_64-darwin-20
@@ -53,7 +136,10 @@ DEPENDENCIES
53
136
  mvc_one!
54
137
  rake (~> 13.0)
55
138
  rspec (~> 3.0)
56
- rubocop (~> 1.21)
139
+ rubocop
140
+ rubocop-rake
141
+ rubocop-rspec
142
+ rubocop-sequel
57
143
 
58
144
  BUNDLED WITH
59
145
  2.4.7
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
data/exe/mvc_one CHANGED
@@ -1,17 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'thor'
3
5
  require 'erb'
4
6
  require 'pry'
5
7
 
6
8
  module MvcOne
7
9
  class MyCLI < Thor
8
- desc "new PROJECT_NAME", "Generate new application"
10
+ desc 'new PROJECT_NAME', 'Generate new application'
9
11
  def new(name)
10
12
  puts "Generating #{name}"
11
13
  project_template(name)
12
14
  end
13
15
 
14
- desc "generate controller/model/view/contract name", "Generate new controller/model/view."
16
+ desc 'generate controller/model/view/contract name', 'Generate new controller/model/view.'
15
17
  def generate(layer, layer_name)
16
18
  case layer
17
19
  when 'controller'
@@ -30,14 +32,16 @@ module MvcOne
30
32
  private
31
33
 
32
34
  def generate_controller(name)
33
- raise Error, 'cd into your project repository' unless Dir.exists? 'app/controllers'
35
+ raise Error, 'cd into your project repository' unless Dir.exist? 'app/controllers'
36
+
34
37
  file_name = "app/controllers/#{name}_controller.rb"
35
38
  template = ERB.new(File.read(File.join(gem_path, 'templates/app/controller_template.erb')))
36
39
  File.write(file_name, template.result(binding))
37
40
  end
38
41
 
39
42
  def generate_model(name)
40
- raise Error, 'cd into your project repository' unless Dir.exists? 'app/models'
43
+ raise Error, 'cd into your project repository' unless Dir.exist? 'app/models'
44
+
41
45
  file_name = "app/models/#{name}.rb"
42
46
  template = ERB.new(File.read(File.join(gem_path, 'templates/app/model_template.erb')))
43
47
  File.write(file_name, template.result(binding))
@@ -47,13 +51,13 @@ module MvcOne
47
51
  name_normalized = name.downcase.gsub(/\s/, '_')
48
52
  make_default_dirs(name_normalized)
49
53
  make_default_files(name_normalized)
50
- template = ERB.new <<-EOF
54
+ template = ERB.new <<-ERBTEMPLATE
51
55
  class ApplicationController
52
56
  def name
53
57
  <%= name %>
54
58
  end
55
59
  end
56
- EOF
60
+ ERBTEMPLATE
57
61
  template.result(binding)
58
62
  end
59
63
 
@@ -78,10 +82,19 @@ module MvcOne
78
82
 
79
83
  gemfile = ERB.new(File.read(File.join(gem_path, 'templates/general/gemfile.erb')))
80
84
  File.write "#{name_normalized}/Gemfile", gemfile.result(binding)
85
+
86
+ app_layout = ERB.new(File.read(File.join(gem_path, 'templates/app/application_layout.slim.erb')))
87
+ File.write "#{name_normalized}/app/views/application_layout.slim", app_layout
88
+
89
+ welcome_controller = ERB.new(File.read(File.join(gem_path, 'templates/app/welcome_controller_rb.erb')))
90
+ File.write "#{name_normalized}/app/controllers/welcome_controller.rb", welcome_controller.result(binding)
91
+
92
+ welcome_index = ERB.new(File.read(File.join(gem_path, 'templates/app/welcome_index.slim')))
93
+ File.write "#{name_normalized}/app/views/welcome/index.slim", welcome_index
81
94
  end
82
95
 
83
96
  def make_default_dirs(root_dir_name)
84
- raise Error, "Project directory already exists: #{root_dir_name}" if Dir.exists? root_dir_name
97
+ raise Error, "Project directory already exists: #{root_dir_name}" if Dir.exist? root_dir_name
85
98
 
86
99
  Dir.mkdir(root_dir_name)
87
100
 
@@ -94,12 +107,11 @@ module MvcOne
94
107
  Dir.mkdir("#{root_dir_name}/app/#{dir_name}")
95
108
  end
96
109
  end
97
- end
98
110
 
99
- def gem_path
100
- File.expand_path("#{File.dirname(__FILE__)}/..")
111
+ def gem_path
112
+ File.expand_path("#{File.dirname(__FILE__)}/..")
113
+ end
101
114
  end
102
115
  end
103
116
 
104
-
105
117
  MvcOne::MyCLI.start(ARGV)
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'rack'
5
+ require 'rack/session'
6
+
7
+ module MvcOne
8
+ # Rack friendly launcher for project
9
+ class Application
10
+ # Main application config
11
+ class Config
12
+ def self.env
13
+ ENV.fetch('APP_ENV', 'development')
14
+ end
15
+
16
+ def self.test?
17
+ env == 'test'
18
+ end
19
+
20
+ def self.secrets
21
+ YAML.load_file('config/secrets.yml')[Application::Config.env]
22
+ end
23
+
24
+ def self.db_config
25
+ YAML.load_file('config/database.yml')[Application::Config.env]
26
+ end
27
+ end
28
+
29
+ def initialize
30
+ @router = RegexpRouter.new(File.join( 'app', 'config', 'routes.rb'))
31
+ end
32
+
33
+ def self.launch
34
+ Rack::Builder.new do |builder|
35
+ builder.use Rack::Session::Cookie, domain: 'localhost', path: '/', expire_after: 3600 * 24,
36
+ secret: Application::Config.secrets['session_cookie']
37
+ builder.run Application.new
38
+ end
39
+ end
40
+
41
+ def call(env)
42
+ request = Rack::Request.new(env)
43
+ result = @router.resolve(request.path, request.request_method)
44
+ controller = result.controller.new(env, result.params, request)
45
+ controller.resolve(result.action)
46
+ end
47
+ end
48
+ end
49
+
50
+ require_relative 'regexp_router'
51
+ require_relative 'contracts/application_contract'
52
+ require_relative 'controllers/application_controller'
53
+ require_relative 'models/application_model'
54
+ require_relative 'repositories/application_relation'
55
+ require_relative 'repositories/application_repository'
56
+ require_relative 'serializers/application_serializer'
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'dry-validation'
4
+
3
5
  # Abstract class for Contract realisation in application
4
- class MvcOne::ApplicationContract < Dry::Validation::Contract
6
+ module MvcOne
7
+ class ApplicationContract < Dry::Validation::Contract
8
+ end
5
9
  end
@@ -4,70 +4,72 @@ require 'slim/include'
4
4
  require 'json'
5
5
 
6
6
  # All app controllers must be subclasses of ApplicationController
7
- class MvcOne::ApplicationController
8
- DEFAULT_LAYOUT = './app/views/application_layout.slim'
9
- DEFAULT_HTTP_CODE = 200
7
+ module MvcOne
8
+ class ApplicationController
9
+ DEFAULT_LAYOUT = './app/views/application_layout.slim'
10
+ DEFAULT_HTTP_CODE = 200
10
11
 
11
- attr_accessor :env
12
- attr_reader :action, :params, :request
12
+ attr_accessor :env
13
+ attr_reader :action, :params, :request
13
14
 
14
- def self.before_action(*methods)
15
- define_method :before_action do
16
- methods.each { |method| send(method) }
15
+ def self.before_action(*methods)
16
+ define_method :before_action do
17
+ methods.each { |method| send(method) }
18
+ end
17
19
  end
18
- end
19
20
 
20
- def initialize(env, params, request)
21
- @env = env
22
- @params = params
23
- @request = request
24
- end
21
+ def initialize(env, params, request)
22
+ @env = env
23
+ @params = params
24
+ @request = request
25
+ end
25
26
 
26
- def resolve(action)
27
- before_action if respond_to?(:before_action)
27
+ def resolve(action)
28
+ before_action if respond_to?(:before_action)
28
29
 
29
- @action = action
30
- send(action)
31
- end
30
+ @action = action
31
+ send(action)
32
+ end
32
33
 
33
- def render(code: DEFAULT_HTTP_CODE, headers: {}, body: nil, layout: DEFAULT_LAYOUT, template: nil)
34
- return [code, headers, [body]] unless body.nil?
34
+ def render(code: DEFAULT_HTTP_CODE, headers: {}, body: nil, layout: DEFAULT_LAYOUT, template: nil)
35
+ return [code, headers, [body]] unless body.nil?
35
36
 
36
- body = prepare_body(layout, template || template_path(action))
37
- [code, headers, [body]]
38
- end
37
+ body = prepare_body(layout, template || template_path(action))
38
+ [code, headers, [body]]
39
+ end
39
40
 
40
- def head(code, headers: {})
41
- [code, headers, []]
42
- end
41
+ def head(code, headers: {})
42
+ [code, headers, []]
43
+ end
43
44
 
44
- def request_params
45
- return @request_params if defined?(@request_params)
46
- return @request_params = {} if request.body.nil?
45
+ def request_params
46
+ return @request_params if defined?(@request_params)
47
+ return @request_params = {} if request.body.nil?
47
48
 
48
- @request_params =
49
- case request.content_type
50
- when 'application/json' then JSON.parse(request.body.read).transform_keys(&:to_sym)
51
- else request.params.transform_keys(&:to_sym)
52
- end
53
- end
49
+ @request_params =
50
+ case request.content_type
51
+ when 'application/json' then JSON.parse(request.body.read).transform_keys(&:to_sym)
52
+ else request.params.transform_keys(&:to_sym)
53
+ end
54
+ end
54
55
 
55
- def render_partial(name, options = {}, &block)
56
- Slim::Template.new("#{name}.slim", options).render(self, &block)
57
- end
56
+ def render_partial(name, options = {}, &block)
57
+ Slim::Template.new("#{name}.slim", options).render(self, &block)
58
+ end
58
59
 
59
- private
60
+ private
60
61
 
61
- def template_path(action)
62
- path = self.class.to_s.delete_suffix('Controller').split('::').map(&:downcase).join('/')
63
- "./app/views/#{path}/#{action}.slim"
64
- end
62
+ def template_path(action)
63
+ path = self.class.to_s.delete_suffix('Controller').split('::').map(&:downcase).join('/')
64
+ "./app/views/#{path}/#{action}.slim"
65
+ end
65
66
 
66
- def prepare_body(layout, template)
67
- return Slim::Template.new(template).render(self) if layout.nil?
67
+ def prepare_body(layout, template)
68
+ return Slim::Template.new(template).render(self) if layout.nil?
68
69
 
69
- Slim::Template.new(layout).render(self) do
70
- Slim::Template.new(template).render(self)
70
+ Slim::Template.new(layout).render(self) do
71
+ Slim::Template.new(template).render(self)
72
+ end
71
73
  end
72
74
  end
73
75
  end
@@ -7,5 +7,7 @@ module Types
7
7
  end
8
8
 
9
9
  # Domain model
10
- class MvcOne::ApplicationModel < Dry::Struct
10
+ module MvcOne
11
+ class ApplicationModel < Dry::Struct
12
+ end
11
13
  end