Skip to content

Commit 2fa42dc

Browse files
committed
Merge branch 'edge' of github.com:hyperstack-org/hyperstack into edge
2 parents d1a65d0 + cb00fb1 commit 2fa42dc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

install/rails-webpacker.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
run 'mkdir app/hyperstack/stores'
2323
run 'mkdir app/hyperstack/models'
2424
run 'mkdir app/hyperstack/operations'
25+
run 'mkdir app/policies'
2526

2627
# ----------------------------------- Add .keep files
2728

@@ -50,6 +51,36 @@ class HyperComponent
5051
config.import 'hyperstack/component/jquery', client_only: true # remove this line if you don't need jquery
5152
config.import 'hyperstack/hotloader', client_only: true if Rails.env.development?
5253
end
54+
55+
# useful for debugging
56+
module Hyperstack
57+
def self.on_error(*args)
58+
::Rails.logger.debug "\033[0;31;1mHYPERSTACK APPLICATION ERROR: #{args.join(", ")}\n"\
59+
"To further investigate you may want to add a debugging "\
60+
"breakpoint in config/initializers/hyperstack.rb\033[0;30;21m"
61+
end
62+
end if Rails.env.development?
63+
CODE
64+
65+
# ----------------------------------- Add a default policy
66+
file 'app/policies/application_policy.rb', <<-CODE
67+
# Policies regulate access to your public models
68+
# The following policy will open up full access (but only in development)
69+
# The policy system is very flexible and powerful. See the documentation
70+
# for complete details.
71+
class Hyperstack::ApplicationPolicy
72+
# Allow any session to connect:
73+
always_allow_connection
74+
# Send all attributes from all public models
75+
regulate_all_broadcasts { |policy| policy.send_all }
76+
# Allow all changes to public models
77+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
78+
# allow remote access to all scopes - i.e. you can count or get a list of ids
79+
# for any scope or relationship
80+
ApplicationRecord.regulate_scope :all
81+
end unless Rails.env.production?
82+
# don't forget to provide a policy before production...
83+
raise "You need to define a Hyperstack policy for production" if Rails.env.production?
5384
CODE
5485

5586
# ----------------------------------- Add NPM modules

0 commit comments

Comments
 (0)