mvc_one 0.1.0.pre.rc2 → 0.1.0.pre.rc4

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: a9156a3747a1449345c6139d1759d2b4666d5eb449daf2eebe37e7f47986d072
4
- data.tar.gz: 3cf5f42bfe96721e029ca91efcf05a1f358b91e5353dea53fe0fdc557e20c4d1
3
+ metadata.gz: 584b655c4c21ec1bc91d22c75ad156d5589192a809cb57e9ef5a6429ece09ea5
4
+ data.tar.gz: d5f3c5067a607a1ad7679e1ac41ab11bad2313a18a090610f7c40dae2f571d42
5
5
  SHA512:
6
- metadata.gz: 28398e4661ba3ba1886acb70073eadfe69544cf0bbc61be2ac0d9a6916aa6a52cbe01fbdc3f44c520381a645ea35f13ea46d5af66d3f9e24eff2bc5c6e5b970d
7
- data.tar.gz: 232cb7052c15497e64225ef73ccef1385eb59f8c23873a64dfa6de18cfae734d08aeb922e1d4bc452156c3b5ecc519e6e7ad2caf11bad7c2c51890e33a8956a9
6
+ metadata.gz: a21a9373694e01b29bf60a578004b3d063c6ace39ec4ab8f1e3adea4dc6c8cd75d4f2d3b30bf7a78dec7bd7a45a58b25bd77f1816f901352d8c48eabd84ebd20
7
+ data.tar.gz: a3ee6770db6b480a0665b6b4ea337abfc2ca6c81845e5e2466d92a4887fa87dd27624ab9bab9805a5245fe8236b475d6681914e913aa6ac956f06bf1b34dc3ba
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.rc4)
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,16 +32,18 @@ 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
- template = ERB.new(File.read('../templates/app/controller_template.erb'))
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
- template = ERB.new(File.read('../templates/app/model_template.erb'))
46
+ template = ERB.new(File.read(File.join(gem_path, 'templates/app/model_template.erb')))
43
47
  File.write(file_name, template.result(binding))
44
48
  end
45
49
 
@@ -47,38 +51,41 @@ 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
 
60
64
  def make_default_files(name_normalized)
61
- config_ru = ERB.new(File.read('templates/general/config_ru.erb'))
65
+ config_ru = ERB.new(File.read(File.join(gem_path, 'templates/general/config_ru.erb')))
62
66
  File.write "#{name_normalized}/config.ru", config_ru.result(binding)
63
67
 
64
- rakefile = ERB.new(File.read('templates/general/rakefile.erb'))
68
+ rakefile = ERB.new(File.read(File.join(gem_path, 'templates/general/rakefile.erb')))
65
69
  File.write "#{name_normalized}/Rakefile", rakefile.result(binding)
66
70
 
67
- application_rb = ERB.new(File.read('templates/general/application_rb.erb'))
68
- File.write "#{name_normalized}/application.rb", config_ru.result(binding)
71
+ application_rb = ERB.new(File.read(File.join(gem_path, 'templates/general/application_rb.erb')))
72
+ File.write "#{name_normalized}/application.rb", application_rb.result(binding)
69
73
 
70
- routes_rb = ERB.new(File.read('templates/config/routes_rb.erb'))
74
+ routes_rb = ERB.new(File.read(File.join(gem_path, 'templates/config/routes_rb.erb')))
71
75
  File.write "#{name_normalized}/app/config/routes.rb", routes_rb.result(binding)
72
76
 
73
- database_yml = ERB.new(File.read('templates/general/database_yml.erb'))
77
+ database_yml = ERB.new(File.read(File.join(gem_path, 'templates/general/database_yml.erb')))
74
78
  File.write "#{name_normalized}/config/database.yml", database_yml.result(binding)
75
79
 
76
- secrets_yml = ERB.new(File.read('templates/general/secrets_yml.erb'))
80
+ secrets_yml = ERB.new(File.read(File.join(gem_path, 'templates/general/secrets_yml.erb')))
77
81
  File.write "#{name_normalized}/config/secrets.yml", secrets_yml.result(binding)
82
+
83
+ gemfile = ERB.new(File.read(File.join(gem_path, 'templates/general/gemfile.erb')))
84
+ File.write "#{name_normalized}/Gemfile", gemfile.result(binding)
78
85
  end
79
86
 
80
87
  def make_default_dirs(root_dir_name)
81
- raise Error, "Project directory already exists: #{root_dir_name}" if Dir.exists? root_dir_name
88
+ raise Error, "Project directory already exists: #{root_dir_name}" if Dir.exist? root_dir_name
82
89
 
83
90
  Dir.mkdir(root_dir_name)
84
91
 
@@ -92,7 +99,10 @@ module MvcOne
92
99
  end
93
100
  end
94
101
  end
95
- end
96
102
 
103
+ def gem_path
104
+ File.expand_path("#{File.dirname(__FILE__)}/..")
105
+ end
106
+ end
97
107
 
98
108
  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(File.dirname(__FILE__), '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