pelita 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86ce8c980f28c6da05cdf73b4cc3632374c2fd84
4
+ data.tar.gz: 4c84e2e6e327a1679d1dad2435a12a8ba5d1d38e
5
+ SHA512:
6
+ metadata.gz: 9bcdf0e320bed15cdcabd62177d8d1e0ccb8ebd820b681a26b2d05f7711e903a64c2fab568ccac2c30110489ee3eb6f5233eaac2c4c2a633a8b771395d9f0bdc
7
+ data.tar.gz: 9d37a79354ca7dff4395cf8afbdd26c7fe0bd4988a0ff11d33aa6ab0aac906d0388e9d3e54838979c21e23d416c7884c9f1faebe39ae8f05019458c1077c89e6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Giovanni Sakti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/PELITA_VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Pelita
2
+
3
+ Pelita is a configurable glue microframework for building API in ruby that focus in simplicity and clarity whilst retaining rails convenience whenever possible.
@@ -0,0 +1,117 @@
1
+ # encoding: utf-8
2
+
3
+ # See https://raw.githubusercontent.com/rails/rails/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb
4
+
5
+ class Object
6
+ # An object is blank if it's false, empty, or a whitespace string.
7
+ # For example, "", " ", +nil+, [], and {} are all blank.
8
+ #
9
+ # This simplifies:
10
+ #
11
+ # if address.nil? || address.empty?
12
+ #
13
+ # ...to:
14
+ #
15
+ # if address.blank?
16
+ def blank?
17
+ respond_to?(:empty?) ? empty? : !self
18
+ end
19
+
20
+ # An object is present if it's not <tt>blank?</tt>.
21
+ def present?
22
+ !blank?
23
+ end
24
+
25
+ # Returns object if it's <tt>present?</tt> otherwise returns +nil+.
26
+ # <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
27
+ #
28
+ # This is handy for any representation of objects where blank is the same
29
+ # as not present at all. For example, this simplifies a common check for
30
+ # HTTP POST/query parameters:
31
+ #
32
+ # state = params[:state] if params[:state].present?
33
+ # country = params[:country] if params[:country].present?
34
+ # region = state || country || 'US'
35
+ #
36
+ # ...becomes:
37
+ #
38
+ # region = params[:state].presence || params[:country].presence || 'US'
39
+ def presence
40
+ self if present?
41
+ end
42
+ end
43
+
44
+ class NilClass
45
+ # +nil+ is blank:
46
+ #
47
+ # nil.blank? # => true
48
+ #
49
+ def blank?
50
+ true
51
+ end
52
+ end
53
+
54
+ class FalseClass
55
+ # +false+ is blank:
56
+ #
57
+ # false.blank? # => true
58
+ #
59
+ def blank?
60
+ true
61
+ end
62
+ end
63
+
64
+ class TrueClass
65
+ # +true+ is not blank:
66
+ #
67
+ # true.blank? # => false
68
+ #
69
+ def blank?
70
+ false
71
+ end
72
+ end
73
+
74
+ class Array
75
+ # An array is blank if it's empty:
76
+ #
77
+ # [].blank? # => true
78
+ # [1,2,3].blank? # => false
79
+ #
80
+ alias_method :blank?, :empty?
81
+ end
82
+
83
+ class Hash
84
+ # A hash is blank if it's empty:
85
+ #
86
+ # {}.blank? # => true
87
+ # {:key => 'value'}.blank? # => false
88
+ #
89
+ alias_method :blank?, :empty?
90
+ end
91
+
92
+ class String
93
+ # 0x3000: fullwidth whitespace
94
+ NON_WHITESPACE_REGEXP = %r![^\s#{[0x3000].pack("U")}]!
95
+
96
+ # A string is blank if it's empty or contains whitespaces only:
97
+ #
98
+ # "".blank? # => true
99
+ # " ".blank? # => true
100
+ # " ".blank? # => true
101
+ # " something here ".blank? # => false
102
+ #
103
+ def blank?
104
+ self !~ NON_WHITESPACE_REGEXP
105
+ end
106
+ end
107
+
108
+ class Numeric #:nodoc:
109
+ # No number is blank:
110
+ #
111
+ # 1.blank? # => false
112
+ # 0.blank? # => false
113
+ #
114
+ def blank?
115
+ false
116
+ end
117
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ class String
4
+ # ruby mutation methods have the expectation to return self if a mutation occurred, nil otherwise. (see http://www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub-21)
5
+ def to_snake_case!
6
+ gsub!(/(.)([A-Z])/,'\1_\2')
7
+ downcase!
8
+ end
9
+
10
+ def to_snake_case
11
+ dup.tap { |s| s.to_snake_case! }
12
+ end
13
+ end
data/lib/core_ext.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'core_ext/blank'
2
+ require_relative 'core_ext/snake_case'
@@ -0,0 +1,16 @@
1
+ class AttemptAdapter < Dry::Transaction::StepAdapters
2
+ include Dry::Monads::Either::Mixin
3
+
4
+ def call(step, input, *args)
5
+ unless step.options[:catch]
6
+ raise ArgumentError, "+attempt+ steps require one or more exception classes provided via +catch:+"
7
+ end
8
+
9
+ step.operation.call(input, *args)
10
+ rescue *Array(step.options[:catch]) => e
11
+ e = step.options[:raise].new(e.message) if step.options[:raise]
12
+ input["error"] = e
13
+ Left(input)
14
+ end
15
+ end
16
+ Dry::Transaction::StepAdapters.register :attempt, AttemptAdapter.new
@@ -0,0 +1,17 @@
1
+ require_relative 'attempt_adapter'
2
+
3
+ module Pelita
4
+ class Operation
5
+ include Dry::Transaction
6
+
7
+ def authorize!(options)
8
+ if options["current_user"].signed_in?
9
+ options["result.policy.default"] = true
10
+ Right(options)
11
+ else
12
+ options["result.policy.default"] = false
13
+ Left(options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require_relative 'operation/base'
data/lib/pelita.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'bcrypt'
2
+ require 'dry-configurable'
3
+ require 'dry-struct'
4
+ require 'dry-transaction'
5
+ require 'dry-validation'
6
+ require 'roda'
7
+ require 'rom'
8
+ require 'rom-repository'
9
+
10
+ require_relative 'core_ext'
11
+ require_relative 'pelita/pelita'
data/pelita.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ version = File.read(File.expand_path("../PELITA_VERSION", __FILE__)).strip
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "pelita"
6
+ spec.summary = %q{No surprise, configurable glue microframework for building API in Ruby}
7
+ spec.description = %q{Pelita is a configurable glue microframework for building API in ruby that focus in simplicity and clarity whilst retaining rails convenience whenever possible}
8
+ spec.license = %q{MIT}
9
+ spec.version = version
10
+
11
+ spec.files = `git ls-files -z`.split("\x0")
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.authors = ["Giovanni Sakti"]
17
+ spec.email = ["giosakti@gmail.com"]
18
+ spec.homepage = "http://github.com/giosakti/pelita"
19
+
20
+ spec.required_ruby_version = '>= 2.3.0'
21
+
22
+ spec.add_dependency "bcrypt", "~> 3.1"
23
+ spec.add_dependency "dotenv", "~> 2.2"
24
+ spec.add_dependency "dry-auto_inject", "~> 0.4"
25
+ spec.add_dependency "dry-configurable", "~> 0.7"
26
+ spec.add_dependency "dry-container", "~> 0.6"
27
+ spec.add_dependency "dry-types", "~> 0.10"
28
+ spec.add_dependency "dry-struct", "~> 0.3"
29
+ spec.add_dependency "dry-system", "~> 0.7"
30
+ spec.add_dependency "dry-validation", "~> 0.10"
31
+ spec.add_dependency "dry-transaction", "~> 0.10"
32
+ spec.add_dependency "rack_csrf", "~> 2.6"
33
+ spec.add_dependency "rack-protection", "~> 2.0"
34
+ spec.add_dependency "rake", "~> 12.0"
35
+ spec.add_dependency "roda", "~> 2.27"
36
+ spec.add_dependency "rom", "~> 3.2"
37
+ spec.add_dependency "rom-repository", "~> 1.3"
38
+ spec.add_dependency "rom-sql", "~> 1.3"
39
+
40
+ spec.add_development_dependency "database_cleaner", "~> 1.6"
41
+ spec.add_development_dependency "rspec", "~> 3.6"
42
+ end
metadata ADDED
@@ -0,0 +1,323 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pelita
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Giovanni Sakti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bcrypt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-auto_inject
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-configurable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dry-container
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dry-types
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dry-struct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: dry-system
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.7'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dry-validation
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.10'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.10'
139
+ - !ruby/object:Gem::Dependency
140
+ name: dry-transaction
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.10'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rack_csrf
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.6'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '2.6'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rack-protection
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '12.0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '12.0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: roda
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '2.27'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '2.27'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rom
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '3.2'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '3.2'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rom-repository
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '1.3'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '1.3'
237
+ - !ruby/object:Gem::Dependency
238
+ name: rom-sql
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: '1.3'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: '1.3'
251
+ - !ruby/object:Gem::Dependency
252
+ name: database_cleaner
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: '1.6'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: '1.6'
265
+ - !ruby/object:Gem::Dependency
266
+ name: rspec
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - "~>"
270
+ - !ruby/object:Gem::Version
271
+ version: '3.6'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - "~>"
277
+ - !ruby/object:Gem::Version
278
+ version: '3.6'
279
+ description: Pelita is a configurable glue microframework for building API in ruby
280
+ that focus in simplicity and clarity whilst retaining rails convenience whenever
281
+ possible
282
+ email:
283
+ - giosakti@gmail.com
284
+ executables: []
285
+ extensions: []
286
+ extra_rdoc_files: []
287
+ files:
288
+ - LICENSE
289
+ - PELITA_VERSION
290
+ - README.md
291
+ - lib/core_ext.rb
292
+ - lib/core_ext/blank.rb
293
+ - lib/core_ext/snake_case.rb
294
+ - lib/pelita.rb
295
+ - lib/pelita/operation/attempt_adapter.rb
296
+ - lib/pelita/operation/base.rb
297
+ - lib/pelita/pelita.rb
298
+ - pelita.gemspec
299
+ homepage: http://github.com/giosakti/pelita
300
+ licenses:
301
+ - MIT
302
+ metadata: {}
303
+ post_install_message:
304
+ rdoc_options: []
305
+ require_paths:
306
+ - lib
307
+ required_ruby_version: !ruby/object:Gem::Requirement
308
+ requirements:
309
+ - - ">="
310
+ - !ruby/object:Gem::Version
311
+ version: 2.3.0
312
+ required_rubygems_version: !ruby/object:Gem::Requirement
313
+ requirements:
314
+ - - ">="
315
+ - !ruby/object:Gem::Version
316
+ version: '0'
317
+ requirements: []
318
+ rubyforge_project:
319
+ rubygems_version: 2.5.2
320
+ signing_key:
321
+ specification_version: 4
322
+ summary: No surprise, configurable glue microframework for building API in Ruby
323
+ test_files: []