culpa 0.8.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWUzODlkNWE4YTE1OWMxNmQyMGZmODBlNzliZTkwMmNmN2MxMGI0ZA==
4
+ ZjYwZmMzMzU5N2FkODlkYWZjYTQ5ZTk2OGU1MzY4ZDFmNDVlOWI4MQ==
5
5
  data.tar.gz: !binary |-
6
- NjdlOGQ4YmY4MDZiNTU1ZWNhZDYyMjY2ZTFjMzAwNGQ3NjY2YjhhYQ==
6
+ YzhkYWM4M2ZlMDk0ZDFiZDMwOTllMzZkNjQyOWFlODZkMmZkNDllOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjIwYWNkZWMxMDJhMTQwNjU5Yjk0NTJjYTNhMTY3ZDQ3NWZmYWQ2NDJjZjZk
10
- NTc5ODM1NGFjYTZhYTAzYTdmN2RlZWRmYWZhMTcxZTdjNzA3MGIzNTU2NTYz
11
- ZjA3N2FhNTM1ZjJiNDJkOTQzOWQxMDViOTAyYzI2NzA0YmFlMjI=
9
+ MDEwYTc1NDcxNjZjNDBlNTMzNWYxYWU0NmY3NmVmMDAxNDRkM2M3ZjY2NGEw
10
+ YTIyZTJhZjQ0NmY2ZDczYzllNmQ4YjI1M2I2YjkyYTAwYTZlNTI5ZjJmYjUw
11
+ MmU0MmUyZWJjNmZmZWFkYTU4YmMyOGNjZmQxNTUwZTcwN2QzZTU=
12
12
  data.tar.gz: !binary |-
13
- M2Y3MjdlZDlhODhlNTgxM2MzOTFmODEyNDFjMGU0ZGY0YTRiNDU1MGQ2Yjlh
14
- NGZhYTljMDYwYzFjOTY3NmFmYzQ1ZDNiYmU4YjYxYTE0NDlkNzE5NzM0ZWFi
15
- YTc0M2E5MDZhMjFmYmYyYzUwMTdmMzc3OTllYmNiMTllYWIzNmU=
13
+ N2M4ZTNkOWZiMzQxNTVkYmEwNjljNTNlZDk1ZTZiMTkzMGJjMGU1OTkwOTE3
14
+ ZmU3MDA1N2FiYTY1YjBhNzBjMDExNTlkYTBhNWQ0OThiNTk2NTcyYmQ3YzYy
15
+ ZTFhNzAzZTY1MTFkZmRmZjBiOGNkNTU3MTg1MGRjZDhkMDMwOWY=
data/bin/culpa CHANGED
@@ -19,7 +19,8 @@ def create_project(project_path)
19
19
  FileUtils.mkdir "#{project_path}/models"
20
20
  FileUtils.touch "#{project_path}/models/.keep"
21
21
  FileUtils.mkdir "#{project_path}/config"
22
- FileUtils.touch "#{project_path}/config/router.yml"
22
+ FileUtils.mkdir "#{project_path}/config/brickchains"
23
+ FileUtils.touch "#{project_path}/config/brickchains/.keep"
23
24
  FileUtils.mkdir "#{project_path}/config/initializers"
24
25
  FileUtils.touch "#{project_path}/config/initializers/.keep"
25
26
 
@@ -65,7 +66,7 @@ def display_help
65
66
  puts 'Commands supported :'
66
67
  puts ' - new [folder] : Creates a new culpa project on the specified folder'
67
68
  puts ' - console : Drops an interactive shell within the running directory'
68
- puts ' - server : Starts the web server'
69
+ puts ' - server : Starts the web server (on the 4748 port)'
69
70
  puts ' - generate : '
70
71
  puts ' - action [action_name] [brick_a brick_b ...] : Creates an action'
71
72
  puts ' - spec : Creates a spec'
data/lib/culpa.rb CHANGED
@@ -7,7 +7,7 @@ require 'envelope'
7
7
  require 'path_parser'
8
8
  require 'file_streamer'
9
9
 
10
- CULPA_VERSION='0.8.0'
10
+ CULPA_VERSION='1.0.0'
11
11
 
12
12
  ACTIONS_PATH ||= './actions/*.rb'
13
13
  MODELS_PATH ||= './models/*.rb'
@@ -24,28 +24,34 @@ module Actions
24
24
  end
25
25
  end
26
26
 
27
- module Models
28
- Dir[MODELS_PATH].each do |file|
29
- require file
30
- end
31
- end
32
-
33
27
  module Culpa
34
28
 
35
29
  class UnpredictableSubCallError < StandardError; end
36
30
  class NoRenderCalled < StandardError; end
37
31
  class UnknownRenderCall < StandardError; end
38
32
 
33
+ Dir[MODELS_PATH].each do |file|
34
+ require file
35
+ end
36
+
39
37
  class Application
40
38
 
41
39
  def initialize(options = {})
42
- @router = YAML.load_file(options[:router] || './config/router.yml')
40
+ @router = {}
41
+ bc_path = options[:brickchains] || './config/brickchains'
42
+ Dir["#{bc_path}/*.yml"].map { |bc_file|
43
+ YAML.load_file(bc_file)
44
+ }.each{ |bc|
45
+ @router.merge!(bc)
46
+ }
43
47
  @logger = Logger.new(options[:log_output] || STDOUT)
44
48
  @logger.level = case ENV['RACK_ENV']
45
49
  when 'development', 'test'
46
50
  Logger::DEBUG
47
51
  else
52
+ # :nocov:
48
53
  Logger::WARN
54
+ # :nocov:
49
55
  end
50
56
  @logger.info 'Culpa fully initialized'
51
57
  end
@@ -66,7 +72,7 @@ module Culpa
66
72
  call_options[:input] = env['rack.input']
67
73
  end
68
74
  # Try the enforced routes
69
- if !(route_params = PathParser.parse('/:res_name', env['PATH_INFO'])).nil?
75
+ if route_params = PathParser.parse('/:res_name', env['PATH_INFO'])
70
76
  call_options[:res_name] = route_params[:res_name]
71
77
  case call_options[:verb]
72
78
  when :get
@@ -76,7 +82,7 @@ module Culpa
76
82
  else
77
83
  raise UnpredictableSubCallError.new
78
84
  end unless call_options.has_key? :sub_call
79
- elsif !(route_params = PathParser.parse('/:res_name/:id', env['PATH_INFO'])).nil?
85
+ elsif route_params = PathParser.parse('/:res_name/:id', env['PATH_INFO'])
80
86
  call_options[:res_name] = route_params[:res_name]
81
87
  call_options[:id] = route_params[:id]
82
88
  case call_options[:verb]
@@ -89,7 +95,7 @@ module Culpa
89
95
  else
90
96
  raise UnpredictableSubCallError.new
91
97
  end unless call_options.has_key? :sub_call
92
- elsif !(route_params = PathParser.parse('/:res_name/:id/:sub_call', env['PATH_INFO'])).nil?
98
+ elsif route_params = PathParser.parse('/:res_name/:id/:sub_call', env['PATH_INFO'])
93
99
  call_options[:res_name] = route_params[:res_name]
94
100
  call_options[:id] = route_params[:id]
95
101
  call_options[:sub_call] = route_params[:sub_call]
data/lib/envelope.rb CHANGED
@@ -25,6 +25,15 @@ module Culpa
25
25
  end
26
26
  end
27
27
 
28
+ def ==(other_envelope)
29
+ return false unless other_envelope.is_a? Envelope
30
+ return false unless other_envelope.instance_variables.count == instance_variables.count
31
+ instance_variables.each do |iv|
32
+ return false unless instance_variable_get(iv) == other_envelope.instance_variable_get(iv)
33
+ end
34
+ return true
35
+ end
36
+
28
37
  end
29
38
 
30
39
  class EnvelopeRequest
@@ -45,7 +54,3 @@ module Culpa
45
54
  end
46
55
 
47
56
  end
48
-
49
-
50
-
51
-
data/lib/path_parser.rb CHANGED
@@ -38,7 +38,6 @@ module Culpa
38
38
  returned
39
39
  end
40
40
 
41
-
42
41
  end
43
42
 
44
- end
43
+ end
data/lib/rspec_helper.rb CHANGED
@@ -4,38 +4,88 @@ require 'rspec/expectations'
4
4
 
5
5
  module CulpaHelpers
6
6
 
7
- class BrickCallMock
8
- def initialize(opts)
9
- @action, @method = opts.first
10
- @action = @action.to_s.split('_').map{|w| w.capitalize}.join
11
- @logger = Logger.new STDOUT
12
- opts.delete(@action)
13
- @envelope = Envelope.new(opts[:envelope]) if opts.has_key? :envelope
14
- @request = EnvelopeRequest.new(opts[:request]) if opts.has_key? :request
7
+ def last_call
8
+ @@last_call
9
+ end
10
+
11
+ def call_brick(brick_name)
12
+ @@last_call = BrickCall.new(brick_name)
13
+ end
14
+
15
+ class BrickCall
16
+
17
+ def initialize(brick_name)
18
+ @brick_name = brick_name.to_s
19
+ end
20
+
21
+ def from(action_const)
22
+ @action_const = action_const
23
+ @envelope = Culpa::Envelope.new()
24
+ @params = Culpa::EnvelopeRequest.new({})
25
+ self
26
+ end
27
+
28
+ # :nocov:
29
+ def and_with_envelope(envelope)
30
+ with_envelope(envelope)
31
+ end
32
+
33
+ def and_with_params(params)
34
+ with_params(params)
35
+ end
36
+ # :nocov:
37
+
38
+ def with_envelope(envelope)
39
+ @envelope = Culpa::Envelope.new(envelope)
40
+ self
41
+ end
42
+
43
+ def with_params(params)
44
+ @params = Culpa::EnvelopeRequest.new(params)
45
+ self
15
46
  end
16
47
 
17
48
  def call
18
- action_class = Actions.const_get(@action).new(@envelope, @request, @logger)
19
- action_class.send @method.to_s
49
+ return @call_cache if @call_done
50
+ @call_done = true
51
+ @action_const.new(@envelope, @params, Logger.new(STDOUT)).send(@brick_name)
52
+ return @call_cache = { to_render: nil, envelope: @envelope }
20
53
  rescue Action::RenderNow => renderer
21
- return renderer.to_render
54
+ return @call_cache = { to_render: renderer.to_render, envelope: @envelope }
22
55
  end
56
+
23
57
  end
24
58
 
25
59
  RSpec::Matchers.define :have_status do |expected|
26
60
  match do |actual|
27
- actual[:status] == Action::RETURN_CODES[expected]
61
+ bc = actual.call
62
+ bc[:to_render][:status] == Action::RETURN_CODES[expected]
28
63
  end
29
64
  end
30
65
 
31
66
  RSpec::Matchers.define :have_headers do |expected|
32
67
  match do |actual|
33
68
  expected.each do |k,v|
34
- return false unless actual[:headers].has_key?(k) and
35
- actual[:headers][k] == expected[k]
69
+ bc = actual.call
70
+ return false unless bc[:to_render][:headers].has_key?(k) and
71
+ bc[:to_render][:headers][k] == expected[k]
36
72
  end
37
73
  true
38
74
  end
39
75
  end
40
76
 
77
+ RSpec::Matchers.define :have_body do |expected|
78
+ match do |actual|
79
+ bc = actual.call
80
+ bc[:to_render][:object] == expected
81
+ end
82
+ end
83
+
84
+ RSpec::Matchers.define :have_envelope do |expected|
85
+ match do |actual|
86
+ bc = actual.call
87
+ bc[:envelope] == Culpa::Envelope.new(expected)
88
+ end
89
+ end
90
+
41
91
  end
data/templates/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'culpa', '~> 0.7'
3
+ gem 'culpa', '~> 1.0'
4
4
 
5
5
  # Use rspec to test your project.
6
6
  gem 'rspec', '~> 3.4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: culpa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérémy SEBAN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.4'
55
- description: Culpa is a framework following MEA principles. Learn more on https://github.com/HipsterWhale/culpa.
55
+ description: Culpa is a framework following MEA principles. Learn more on http://culpaframework.org/.
56
56
  email: jeremy@seban.eu
57
57
  executables:
58
58
  - culpa
@@ -70,7 +70,7 @@ files:
70
70
  - templates/Gemfile
71
71
  - templates/config.ru
72
72
  - templates/generators/action.tmpl
73
- homepage: https://github.com/HipsterWhale/culpa
73
+ homepage: http://culpaframework.org/
74
74
  licenses:
75
75
  - MIT
76
76
  metadata: {}