trailblazer 1.0.0.rc2 → 1.0.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
2
  SHA1:
3
- metadata.gz: 07471cd851403f80b0a26ef761be0ceb009dc745
4
- data.tar.gz: cad5f9dfb9a3e6ecce4623d4d32bff7688ac62e0
3
+ metadata.gz: 706f11d67b247409077b6cf7dd236ee0cbb67490
4
+ data.tar.gz: 02c05af733cceef4436e35f018a71e667ef45db5
5
5
  SHA512:
6
- metadata.gz: 7896872cf410a207510668b7589f5e39b45c7d5ae3180682ecd5036745646742ccf1c487a26b7df5407f57ef8c12c94832948d22746472a463ce0a42c7be1594
7
- data.tar.gz: 35a858f63b046ff83c7f456e043ccefa1f10e52a0e84c5ac967dfeed36987c03fb8c0a909552060363335779080536a59e7d6c82669a07636fd86012ea532762
6
+ metadata.gz: 389626ff14345d9a37ca9159ecce584233d74ccb09248f34eb09a332af95bf9457b13dcf653a8579d23bc45ee92e778f8c19218665167c768e8b8961f4ef4dfb
7
+ data.tar.gz: 5ec3b0a491cf5a56159f79463a15f88971ef53ef9e72984d9c2a3aec627fdbefd8c2de58eeed9e5cfc3a6747e2f7e59d4635bf1a9e736c7f6f586eef6617243e
data/CHANGES.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # 1.0.0
2
2
 
3
+ * All Rails-relevant files are now in the `trailblazer-rails` gem. You have to include it should you be in a Rails environment.
3
4
  * `Operation[{..}]` is deprecated in favor of `Operation.({..})`.
4
- setup in initialize: when Op.run() with Worker, the policy will be run "delayed" and not with the actual permission set. this will result in many crashing sidekiq workers.
5
5
  * `Operation::CRUD` is now `Operation::Model`.
6
6
  * `Controller#form` now invokes `#prepopulate!` before rendering the view.
7
7
  * `Controller#present` does not instantiate and assign `@form` anymore.
8
+ * The internal `Operation` API has changed from `#initialize()` and `#run(params)` to `#initialize(params)` and `#run`.
8
9
 
9
10
  # 0.3.4
10
11
 
data/Rakefile CHANGED
@@ -1,23 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- task :default => [:build]
5
- default_task = Rake::Task[:build]
4
+ task :default => [:test]
6
5
 
7
6
  Rake::TestTask.new(:test) do |test|
8
7
  test.libs << 'test'
9
- test.test_files = FileList['test/*_test.rb', "test/operation/**/*_test.rb"]
8
+ test.test_files = FileList['test/**/*_test.rb']
10
9
  test.verbose = true
11
- end
12
-
13
- # this how the rails test must be run: BUNDLE_GEMFILE=gemfiles/Gemfile.rails bundle exec rake rails
14
- Rake::TestTask.new(:rails) do |test|
15
- test.libs << 'test/rails'
16
- test.test_files = FileList['test/rails/*_test.rb']
17
- test.verbose = true
18
- end
19
-
20
- rails_task = Rake::Task["rails"]
21
- test_task = Rake::Task["test"]
22
- default_task.enhance { test_task.invoke }
23
- default_task.enhance { rails_task.invoke }
10
+ end
@@ -1,6 +1,5 @@
1
1
  Trailblazer::Operation.class_eval do
2
2
  autoload :Controller, "trailblazer/operation/controller"
3
- autoload :Responder, "trailblazer/operation/responder"
4
3
  autoload :Model, "trailblazer/operation/model"
5
4
  autoload :Collection, "trailblazer/operation/collection"
6
5
  autoload :Dispatch, "trailblazer/operation/dispatch"
@@ -4,15 +4,10 @@ module Trailblazer
4
4
  class Operation
5
5
  require "trailblazer/operation/builder"
6
6
  extend Builder # imports ::builder_class and ::build_operation.
7
+
7
8
  extend Uber::InheritableAttr
8
9
  inheritable_attr :contract_class
9
10
  self.contract_class = Reform::Form.clone
10
- self.contract_class.class_eval do
11
- def self.name # FIXME: don't use ActiveModel::Validations in Reform, it sucks.
12
- # for whatever reason, validations climb up the inheritance tree and require _every_ class to have a name (4.1).
13
- "Reform::Form"
14
- end
15
- end
16
11
 
17
12
  class << self
18
13
  def run(params, &block) # Endpoint behaviour
@@ -1,3 +1,3 @@
1
1
  module Trailblazer
2
- VERSION = "1.0.0.rc2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -16,7 +16,6 @@ class DslRepresenterTest < MiniTest::Spec
16
16
  describe "inheritance across operations" do
17
17
  class Operation < Trailblazer::Operation
18
18
  include Representer
19
- include Responder
20
19
  include SongProcess
21
20
 
22
21
  representer do
data/test/test_helper.rb CHANGED
@@ -1,60 +1,5 @@
1
1
  require 'trailblazer'
2
2
  require 'minitest/autorun'
3
- require 'active_record'
4
- require 'database_cleaner'
5
-
6
- require 'fileutils'
7
- FileUtils::mkdir_p '/tmp/uploads'
8
-
9
- # ActiveRecord Connection
10
- # ActiveRecord::Base.logger = Logger.new(STDERR)
11
- ActiveRecord::Base.logger = false
12
- ActiveRecord::Base.establish_connection(
13
- adapter: "sqlite3",
14
- database: ":memory:"
15
- )
16
-
17
- # Dot not show Active Record Migrations
18
- ActiveRecord::Migration.verbose = false
19
- ActiveRecord::Schema.define do
20
- create_table :things do |table|
21
- table.column :title, :string
22
- table.column :active, :boolean, default: true
23
- end
24
-
25
- create_table(:bands) do |table|
26
- table.column :name, :string
27
- table.column :locality, :string
28
- end
29
- end
30
-
31
- module TmpUploads
32
- extend ActiveSupport::Concern
33
-
34
- included do
35
- let (:tmp_dir) { "/tmp/uploads" }
36
- before { Dir.mkdir(tmp_dir) unless File.exists?(tmp_dir) }
37
- end
38
- end
39
-
40
- MiniTest::Spec.class_eval do
41
- include TmpUploads
42
- end
43
-
44
- # Database Cleaning
45
- DatabaseCleaner.strategy = :transaction
46
- DatabaseCleaner.clean_with(:truncation)
47
-
48
- class MiniTest::Spec
49
- before :each do
50
- DatabaseCleaner.start
51
- end
52
-
53
- after :each do
54
- DatabaseCleaner.clean
55
- end
56
- end
57
-
58
3
 
59
4
  require "reform/form/active_model/validations"
60
5
  Reform::Form.class_eval do
data/trailblazer.gemspec CHANGED
@@ -19,17 +19,14 @@ Gem::Specification.new do |spec|
19
19
 
20
20
 
21
21
  spec.add_dependency "uber", ">= 0.0.15"
22
- # spec.add_dependency "representable", ">= 2.1.1", "<2.3.0" # Representable::apply.
23
22
  spec.add_dependency "reform", ">= 1.2.0"
24
23
 
24
+ spec.add_development_dependency "activemodel" # for Reform::AM::V
25
+
25
26
  spec.add_development_dependency "bundler"
26
27
  spec.add_development_dependency "rake"
27
28
  spec.add_development_dependency "minitest"
28
- spec.add_development_dependency "sidekiq", ">= 3.1.0"
29
- spec.add_development_dependency "actionpack", '>= 3.0.0' # Rails is optional.
30
- spec.add_development_dependency "rails"
31
29
  spec.add_development_dependency "sqlite3"
32
- spec.add_development_dependency "responders"
33
30
  spec.add_development_dependency "database_cleaner"
34
31
 
35
32
  spec.add_development_dependency "roar"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: minitest
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,35 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: sidekiq
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 3.1.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 3.1.0
97
- - !ruby/object:Gem::Dependency
98
- name: actionpack
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 3.0.0
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 3.0.0
111
- - !ruby/object:Gem::Dependency
112
- name: rails
84
+ name: minitest
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
@@ -136,20 +108,6 @@ dependencies:
136
108
  - - ">="
137
109
  - !ruby/object:Gem::Version
138
110
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: responders
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
111
  - !ruby/object:Gem::Dependency
154
112
  name: database_cleaner
155
113
  requirement: !ruby/object:Gem::Requirement
@@ -206,7 +164,6 @@ files:
206
164
  - lib/trailblazer/operation/builder.rb
207
165
  - lib/trailblazer/operation/collection.rb
208
166
  - lib/trailblazer/operation/controller.rb
209
- - lib/trailblazer/operation/controller/active_record.rb
210
167
  - lib/trailblazer/operation/dispatch.rb
211
168
  - lib/trailblazer/operation/model.rb
212
169
  - lib/trailblazer/operation/model/dsl.rb
@@ -216,14 +173,10 @@ files:
216
173
  - lib/trailblazer/operation/policy/guard.rb
217
174
  - lib/trailblazer/operation/representer.rb
218
175
  - lib/trailblazer/operation/resolver.rb
219
- - lib/trailblazer/operation/responder.rb
220
176
  - lib/trailblazer/operation/uploaded_file.rb
221
- - lib/trailblazer/operation/worker.rb
222
177
  - lib/trailblazer/version.rb
223
178
  - test/collection_test.rb
224
179
  - test/dispatch_test.rb
225
- - test/fixtures/apotomo.png
226
- - test/fixtures/cells.png
227
180
  - test/model_test.rb
228
181
  - test/module_test.rb
229
182
  - test/operation/builder_test.rb
@@ -237,27 +190,9 @@ files:
237
190
  - test/operation/reject_test.rb
238
191
  - test/operation/resolver_test.rb
239
192
  - test/operation_test.rb
240
- - test/rails/__respond_test.rb
241
- - test/rails/controller_test.rb
242
- - test/rails/endpoint_test.rb
243
- - test/rails/fake_app/app-cells/.gitkeep
244
- - test/rails/fake_app/cells.rb
245
- - test/rails/fake_app/config.rb
246
- - test/rails/fake_app/controllers.rb
247
- - test/rails/fake_app/models.rb
248
- - test/rails/fake_app/rails_app.rb
249
- - test/rails/fake_app/song/operations.rb
250
- - test/rails/fake_app/views/bands/index.html.erb
251
- - test/rails/fake_app/views/songs/another_view.html.erb
252
- - test/rails/fake_app/views/songs/new.html.erb
253
- - test/rails/respond_test.rb
254
- - test/rails/test_helper.rb
255
193
  - test/representer_test.rb
256
- - test/responder_test.rb
257
194
  - test/rollback_test.rb
258
195
  - test/test_helper.rb
259
- - test/uploaded_file_test.rb
260
- - test/worker_test.rb
261
196
  - trailblazer.gemspec
262
197
  homepage: http://www.trailblazerb.org
263
198
  licenses:
@@ -274,9 +209,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
209
  version: '0'
275
210
  required_rubygems_version: !ruby/object:Gem::Requirement
276
211
  requirements:
277
- - - ">"
212
+ - - ">="
278
213
  - !ruby/object:Gem::Version
279
- version: 1.3.1
214
+ version: '0'
280
215
  requirements: []
281
216
  rubyforge_project:
282
217
  rubygems_version: 2.4.8
@@ -286,8 +221,6 @@ summary: A new architecture for Rails.
286
221
  test_files:
287
222
  - test/collection_test.rb
288
223
  - test/dispatch_test.rb
289
- - test/fixtures/apotomo.png
290
- - test/fixtures/cells.png
291
224
  - test/model_test.rb
292
225
  - test/module_test.rb
293
226
  - test/operation/builder_test.rb
@@ -301,25 +234,7 @@ test_files:
301
234
  - test/operation/reject_test.rb
302
235
  - test/operation/resolver_test.rb
303
236
  - test/operation_test.rb
304
- - test/rails/__respond_test.rb
305
- - test/rails/controller_test.rb
306
- - test/rails/endpoint_test.rb
307
- - test/rails/fake_app/app-cells/.gitkeep
308
- - test/rails/fake_app/cells.rb
309
- - test/rails/fake_app/config.rb
310
- - test/rails/fake_app/controllers.rb
311
- - test/rails/fake_app/models.rb
312
- - test/rails/fake_app/rails_app.rb
313
- - test/rails/fake_app/song/operations.rb
314
- - test/rails/fake_app/views/bands/index.html.erb
315
- - test/rails/fake_app/views/songs/another_view.html.erb
316
- - test/rails/fake_app/views/songs/new.html.erb
317
- - test/rails/respond_test.rb
318
- - test/rails/test_helper.rb
319
237
  - test/representer_test.rb
320
- - test/responder_test.rb
321
238
  - test/rollback_test.rb
322
239
  - test/test_helper.rb
323
- - test/uploaded_file_test.rb
324
- - test/worker_test.rb
325
240
  has_rdoc:
@@ -1,16 +0,0 @@
1
- # Assigns an additional instance variable for +@model+ named after the model's table name (e.g. @comment).
2
- module Trailblazer::Operation::Controller::ActiveRecord
3
- private
4
- def setup_operation_instance_variables!(operation, options)
5
- super
6
- instance_variable_set(:"@#{operation_model_name}", @model)
7
- end
8
-
9
- def operation_model_name
10
- # set the right variable name if collection
11
- if @operation.is_a?(Trailblazer::Operation::Collection)
12
- return @model.model.table_name.split(".").last
13
- end
14
- @model.class.table_name.split(".").last.singularize
15
- end
16
- end
@@ -1,23 +0,0 @@
1
- module Trailblazer::Operation::Responder
2
- def self.included(base)
3
- base.extend ClassMethods
4
- end
5
-
6
- module ClassMethods
7
- def model_name
8
- model_class.model_name
9
- end
10
- end
11
-
12
- extend Forwardable
13
- def_delegators :@model, :to_param, :destroyed?, :persisted?
14
-
15
- def errors
16
- return [] if @valid
17
- [1]
18
- end
19
-
20
- def to_model
21
- @model
22
- end
23
- end
@@ -1,111 +0,0 @@
1
- require 'sidekiq/worker'
2
- require 'active_support/core_ext/hash/indifferent_access'
3
-
4
-
5
- class Trailblazer::Operation
6
- # only kicks in when Operation::run, #run will still do it real-time
7
- # Works with Reform 2, only.
8
- module Worker
9
- def self.included(base)
10
- base.send(:include, Sidekiq::Worker)
11
- base.extend(ClassMethods)
12
- end
13
-
14
- module ClassMethods
15
- def run(params)
16
- if background?
17
- return perform_async(serializable(params))
18
- end
19
-
20
- super(params)
21
- end
22
-
23
- def new(*args)
24
- return super if args.any?
25
- # sidekiq behavior: (not a big fan of this)
26
- self
27
- end
28
-
29
- def perform(params) # called by Sidekiq.
30
- build_operation(params).perform
31
- end
32
-
33
- def jid=(jid)
34
- puts "@@@@@ #{jid.inspect}"
35
- end
36
-
37
- private
38
- def perform_async(*args)
39
- client_push('class' => self, 'args' => args) # calls class.new.perform(params)
40
- end
41
-
42
- def background? # TODO: make configurable.
43
- true
44
- # if Rails.env == "production" or Rails.env == "staging"
45
- end
46
-
47
- def serializable(params)
48
- params # this is where we convert file uloads into Trailblazer::UploadedFile, etc. soon.
49
- end
50
- end
51
-
52
-
53
- def perform#(params)
54
- # the serialized params hash from Sidekiq contains a Op::UploadedFile hash.
55
-
56
- # the following code is basically what happens in a controller.
57
- # this is a bug in Rails, it doesn't work without requiring as/hash/ina
58
- # params = ActiveSupport::HashWithIndifferentAccess.new_from_hash_copying_default(params) # TODO: this might make it ultra-slow as Reform converts it back to strings.
59
- params = @params.with_indifferent_access
60
- @params = deserializable(params)
61
- run
62
- end
63
-
64
- private
65
- def deserializable(params)
66
- params # this is where we convert file uloads into Trailblazer::UploadedFile, etc. soon.
67
- end
68
-
69
-
70
- # Overrides ::serializable and #deserializable and handles file properties from the Contract schema.
71
- module FileMarshaller
72
- # NOTE: this is WIP and the implementation will be more understandable and performant soon.
73
- def self.included(base)
74
- base.extend ClassMethods
75
- end
76
-
77
-
78
- private
79
- module ClassMethods
80
- def file_marshaller_representer
81
- @file_marshaller_representer ||= contract_class.schema(include: [Representable::Hash]).apply do |dfn|
82
- dfn.merge!(
83
- getter: lambda { |*| self[dfn.name.to_sym] },
84
- setter: lambda { |fragment, *| self[dfn.name.to_s] = fragment }
85
- ) # FIXME: allow both sym and str.
86
-
87
- dfn.merge!(class: Hash) and next if dfn[:form] or dfn[:twin] # nested properties need a class for deserialization.
88
- next unless dfn[:file]
89
-
90
- # TODO: where do we set /tmp/uploads?
91
- dfn.merge!(
92
- serialize: lambda { |file, *| Trailblazer::Operation::UploadedFile.new(file, tmp_dir: "/tmp/uploads").to_hash },
93
- deserialize: lambda { |object, hash, *| Trailblazer::Operation::UploadedFile.from_hash(hash) },
94
- class: Hash
95
- )
96
- end
97
- end
98
-
99
- def serializable(params)
100
- file_marshaller_representer.new(params).to_hash
101
- end
102
- end
103
-
104
- # todo: do with_indifferent_access in #deserialize and call super here.
105
- def deserializable(hash)
106
- # self.class.file_marshaller_representer.new({}).extend(Representable::Debug).from_hash(hash)
107
- self.class.file_marshaller_representer.new({}.with_indifferent_access).from_hash(hash)
108
- end
109
- end
110
- end
111
- end