Skip to content

Commit 691a1f4

Browse files
committedJun 13, 2019
closes #196 and cleans up install docs and generator
1 parent a0265eb commit 691a1f4

File tree

5 files changed

+80
-26
lines changed

5 files changed

+80
-26
lines changed
 

‎docs/installation/installation.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ For any setup you need
88

99
#### - Rails 5.x ([Install Instructions](http://railsinstaller.org/en))
1010

11+
> if anybody can confirm or deny that NodeJS is actually needed for a basic install just to
12+
display a component, please let us know by either chatting, tweeting #hyperstack, or raising an issue.
13+
1114
And for a full system that includes Webpack for managing javascript assets you will need
1215

13-
#### - Yarn ([Install Instructions](https://yarnpkg.com/en/docs/install#mac-stable))
16+
#### - Yarn ([Install Instructions](https://yarnpkg.com/en/docs/install))
17+
#### - NodeJS: ([Install Instructions](https://nodejs.org))
18+
1419

1520
## Creating a Test Rails App
1621

@@ -305,7 +310,9 @@ work the same, but just generate different skeleton components.
305310

306311
Using the Rails `webpacker` gem you can easily add other NPM (node package manager) assets to your Hyperstack application. This allows your Hyperstack components to use any of the thousands of existing React component libraries, as well as packages like jQuery.
307312

308-
> Note that you will need to have yarn installed: [Install Instructions](https://yarnpkg.com/en/docs/install#mac-stable)
313+
> Note that you will need to have yarn and nodejs installed:
314+
> [Yarn Install Instructions](https://yarnpkg.com/en/docs/install)
315+
> [Node Install Instructions](https://nodejs.org)
309316
310317
For details on how to import and use NPM packages in your application see [Importing React Components](https://hyperstack.org/edge/docs/dsl-client/components#javascript-components)
311318

@@ -322,12 +329,13 @@ This will do the following:
322329

323330
These steps are explained in detailed below.
324331

325-
#### Yarn
332+
#### Yarn and Node
326333

327334
Yarn is an NPM package manager. Its role is similar to bundler in the Ruby world. Like bundler it uses a `.lock` file to track the current set of dependencies. Unlike
328-
bundler there is no equivilent of the `Gem` file. Instead you add packages directly into the yarn data base by running `yarn add` commands.
335+
bundler there is no equivilent of the `Gem` file. Instead you add packages directly into the yarn data base by running `yarn add` commands. Yarn also depends on NodeJS so you will need to install that if you have not already.
329336

330-
Yarn can be installed following these instructions: [Install Instructions](https://yarnpkg.com/en/docs/install#mac-stable)
337+
Yarn can be installed following these instructions: [Install Instructions](https://yarnpkg.com/en/docs/install#mac-stable)
338+
Node can be installed following these instructions: [Node Install Instructions](https://nodejs.org)
331339

332340
#### The Webpacker Gem
333341

‎ruby/hyper-model/lib/reactive_record/active_record/reactive_record/collection.rb

+10-17
Original file line numberDiff line numberDiff line change
@@ -588,25 +588,8 @@ def loading?
588588
@dummy_collection.loading?
589589
end
590590

591-
# def loading?
592-
# !@collection || (@dummy_collection && @dummy_collection.loading?) || (@owner && !@owner.id && @vector && @vector.length <= 1)
593-
# end
594-
595-
# def loaded?
596-
# @collection && (!@dummy_collection || !@dummy_collection.loading?) && (!@owner || @owner.id || !@vector || @vector.length > 1)
597-
# #false && @collection && (!@dummy_collection || !@dummy_collection.loading?) && (!@owner || @owner.id || @vector.length > 1)
598-
# end
599-
600-
def empty?
601-
# should be handled by method missing below, but opal-rspec does not deal well
602-
# with method missing, so to test...
603-
all.empty?
604-
end
605-
606591
def find_by(attrs)
607592
attrs = @target_klass.__hyperstack_preprocess_attrs(attrs)
608-
# r = @collection&.detect { |lr| lr.new_record? && !attrs.detect { |k, v| lr.attributes[k] != v } }
609-
# return r if r
610593
(r = __hyperstack_internal_scoped_find_by(attrs)) || return
611594
r.backing_record.sync_attributes(attrs).set_ar_instance!
612595
end
@@ -627,6 +610,16 @@ def _find_by_initializer(scope, attrs)
627610
found
628611
end
629612

613+
# to avoid fetching the entire collection array we check empty and any against the count
614+
615+
def empty?
616+
count.zero?
617+
end
618+
619+
def any?
620+
!count.zero?
621+
end
622+
630623
def method_missing(method, *args, &block)
631624
if args.count == 1 && method.start_with?('find_by_')
632625
find_by(method.sub(/^find_by_/, '') => args[0])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require 'spec_helper'
2+
require 'test_components'
3+
require 'rspec-steps'
4+
5+
RSpec::Steps.steps "collection aggregate methods", js: true do
6+
7+
before(:all) do
8+
require 'pusher'
9+
require 'pusher-fake'
10+
Pusher.app_id = "MY_TEST_ID"
11+
Pusher.key = "MY_TEST_KEY"
12+
Pusher.secret = "MY_TEST_SECRET"
13+
require "pusher-fake/support/base"
14+
15+
Hyperstack.configuration do |config|
16+
config.transport = :pusher
17+
config.channel_prefix = "synchromesh"
18+
config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
19+
end
20+
end
21+
22+
before(:step) do
23+
# spec_helper resets the policy system after each test so we have to setup
24+
# before each test
25+
stub_const 'TestApplication', Class.new
26+
stub_const 'TestApplicationPolicy', Class.new
27+
TestApplicationPolicy.class_eval do
28+
always_allow_connection
29+
regulate_all_broadcasts { |policy| policy.send_all }
30+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
31+
end
32+
size_window(:small, :portrait)
33+
end
34+
35+
[:count, :empty?, :any?].each do |method|
36+
it "will not retrieve the entire collection when using #{method}" do
37+
FactoryBot.create(:test_model)
38+
39+
expect_promise(<<-RUBY
40+
Hyperstack::Model
41+
.load { TestModel.#{method} }
42+
.then do |val|
43+
if TestModel.all.instance_variable_get('@collection')
44+
"unnecessary fetch of all"
45+
else
46+
val
47+
end
48+
end
49+
RUBY
50+
).to eq(TestModel.all.send(method))
51+
end
52+
end
53+
end

‎ruby/rails-hyperstack/lib/generators/hyperstack/install_generator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def insure_yarn_loaded
4343
yarn_version = `yarn --version`
4444
raise Errno::ENOENT if yarn_version.blank?
4545
rescue Errno::ENOENT
46-
raise Thor::Error.new("please insure the yarn command is available if using webpacker")
46+
raise Thor::Error.new("please insure nodejs is installed and the yarn command is available if using webpacker")
4747
end
4848
end
4949

‎ruby/rails-hyperstack/rails-hyperstack.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Welcome to Hyperstack!
2525
2626
For a quick start simply add a component using one of the generators:
2727
28-
>> bundle exec rails generate hyper:component CompName --add-route=/test/(*others)
28+
>> bundle exec rails generate hyper:component CompName --add-route="/test/(*others)"
2929
# Add a new component named CompName and route to it with /test/
3030
31-
>> bundle exec rails generate hyper:router CompName --add-route=/test/(*others)
32-
# Add a top level router named CompName
31+
>> bundle exec rails generate hyper:router CompName --add-route="/test/(*others)"
32+
# Add a top level router named CompName and route to it
3333
3434
The generators will insure you have the minimal additions to your system for the
3535
new component to run. And note: --add-route is optional.

0 commit comments

Comments
 (0)
Please sign in to comment.