hai 0.0.3 → 0.0.4

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd1e9a5e790765b1b2030e4384048a2ad08f420e2078b5d883e2bffd2d8dc8eb
4
- data.tar.gz: 4da9e653d8c708d2e01135aa8cbf70234ec73100a0c158cb3dbd1583a47add28
3
+ metadata.gz: f748b48e465a88f0d1ff069c711d9ea21e0ac855e6a261bb29cf0a8e52e75585
4
+ data.tar.gz: ad117a23c477fec0ec5494b7bda4d1143a4698fbd7796cffebbb0995d25571db
5
5
  SHA512:
6
- metadata.gz: dda8bcf71ee7a008b7fac3c6ad0f83b25e3d4fb3c50078b7cae6e1d9d896fa1d3d88b18eacced38fe7ce2e7e6c1efd55c02dc6187934376ab03e7f28f7ed7af4
7
- data.tar.gz: f125a58684eeba263730397623dd1f3fa58b1168423960c88cb5a0d4f815f6312c18d470d558c8cb8f9a992d542b60637c2086dd4487b0b8737ea48db0c19015
6
+ metadata.gz: bfa8f4be0c3bbeb2719113b19a25a8b5846ff0013daa93f8f9c965463c2a26776ef1044b2628c7e39d0d77be069089be729a1351a5d697a2d71f8b1b2c91df1a
7
+ data.tar.gz: 0a07c759c76f2fc8dd347be3f3e5b1760a7eacead3dd199abae296bf0aa608e172916d0a419f4021732f33d7db3f8c5de9cb196dcd14aacd56f7277e723a510e
data/README.md CHANGED
@@ -21,7 +21,8 @@ And then execute:
21
21
 
22
22
  Hai is a resource based api and those resources are ActiveRecord models. Keeping with this first principle, let's see how it can be used in your Ruby application.
23
23
 
24
- ## Action Modifications
24
+ <details>
25
+ <summary>Action Modifications </summary>
25
26
 
26
27
  If you want to modify any of the actions, you can add a Actions module to the
27
28
  model that you want to modify.
@@ -49,7 +50,10 @@ class Post < ApplicationRecord
49
50
  end
50
51
  end
51
52
  ```
52
- ## Policies
53
+ </details>
54
+
55
+ <details>
56
+ <summary> Policies</summary>
53
57
  Policies are handled in the same manner of Action Modifications. We will use the `Policies` module in the model to handle things like authorization.
54
58
 
55
59
  ```ruby
@@ -84,8 +88,10 @@ class Post < ApplicationRecord
84
88
  end
85
89
  end
86
90
  ```
91
+ </details>
87
92
 
88
- ## Graphql
93
+ <details>
94
+ <summary>Graphql</summary>
89
95
 
90
96
  Hai Graphql depends on `graphql-ruby` so if you don't have that installed and
91
97
  boostrapped, head over to [ their repo and do that now ](https://github.com/rmosolgo/graphql-ruby#installation).
@@ -128,8 +134,11 @@ module Types
128
134
  end
129
135
  end
130
136
  ```
137
+ </details>
138
+
139
+ <details>
131
140
 
132
- ## Rest
141
+ <summary>Rest</summary>
133
142
 
134
143
  This is even easier than adding Hai Graphql. Hai Rest is a dynamic engine that can be mounted with any namespace. You just have to mount it in your routes file like this:
135
144
 
@@ -192,6 +201,9 @@ Or all things combined
192
201
  #### Delete a user
193
202
  `DELETE <base_url>/rest/users/1`
194
203
 
204
+ </details>
205
+
206
+
195
207
  ## Development
196
208
 
197
209
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -53,6 +53,10 @@ module Hai
53
53
 
54
54
  private
55
55
 
56
+ def context
57
+ try(:super) || {}
58
+ end
59
+
56
60
  def model_class
57
61
  params[:model].classify.constantize
58
62
  end
@@ -45,7 +45,7 @@ module Hai
45
45
 
46
46
  klass = Class.new(::Types::BaseObject)
47
47
  model.attribute_types.each do |attr, type|
48
- klass.send(:field, attr, Hai::GraphQL::TYPE_CAST[type.class])
48
+ klass.send(:field, attr, Hai::GraphQL::TYPE_CAST[type.class] || Hai::GraphQL::TYPE_CAST[type.class.superclass])
49
49
  rescue ArgumentError => e
50
50
  binding.pry
51
51
  end
@@ -80,7 +80,7 @@ module Hai
80
80
 
81
81
  klass.argument(
82
82
  attr,
83
- Hai::GraphQL::TYPE_CAST[type.class],
83
+ Hai::GraphQL::TYPE_CAST[type.class]|| Hai::GraphQL::TYPE_CAST[type.class.superclass],
84
84
  required: false
85
85
  )
86
86
  end
data/lib/hai/graphql.rb CHANGED
@@ -15,6 +15,7 @@ module Hai
15
15
  ActiveModel::Type::Integer => ::GraphQL::Types::Int,
16
16
  ActiveModel::Type::Float => ::GraphQL::Types::Float,
17
17
  ActiveModel::Type::String => ::GraphQL::Types::String,
18
+ ActiveRecord::Type::Text => ::GraphQL::Types::String,
18
19
  ActiveModel::Type::Boolean => ::GraphQL::Types::Boolean,
19
20
  ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter =>
20
21
  ::GraphQL::Types::ISO8601DateTime
@@ -23,6 +24,7 @@ module Hai
23
24
  ActiveModel::Type::Integer => Hai::GraphQL::Types::Arel::IntInputType,
24
25
  ActiveModel::Type::Float => Hai::GraphQL::Types::Arel::FloatInputType,
25
26
  ActiveModel::Type::String => Hai::GraphQL::Types::Arel::StringInputType,
27
+ ActiveRecord::Type::Text => Hai::GraphQL::Types::Arel::StringInputType,
26
28
  ActiveModel::Type::Boolean => Hai::GraphQL::Types::Arel::BooleanInputType,
27
29
  ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter =>
28
30
  Hai::GraphQL::Types::Arel::DateTimeInputType
@@ -33,15 +35,19 @@ module Hai
33
35
  end
34
36
 
35
37
  module ClassMethods
36
- def hai_query(model)
37
- Hai::GraphQL::ReadQueries.add(self, model)
38
- Hai::GraphQL::ListQueries.add(self, model)
38
+ def hai_query(*models)
39
+ models.each do |model|
40
+ Hai::GraphQL::ReadQueries.add(self, model)
41
+ Hai::GraphQL::ListQueries.add(self, model)
42
+ end
39
43
  end
40
44
 
41
- def hai_mutation(model)
42
- Hai::GraphQL::CreateMutations.add(self, model)
43
- Hai::GraphQL::UpdateMutations.add(self, model)
44
- Hai::GraphQL::DeleteMutations.add(self, model)
45
+ def hai_mutation(*models)
46
+ models.each do |model|
47
+ Hai::GraphQL::CreateMutations.add(self, model)
48
+ Hai::GraphQL::UpdateMutations.add(self, model)
49
+ Hai::GraphQL::DeleteMutations.add(self, model)
50
+ end
45
51
  end
46
52
  end
47
53
  end
data/lib/hai/read.rb CHANGED
@@ -34,7 +34,7 @@ module Hai
34
34
 
35
35
  private
36
36
 
37
- def check_read_policy
37
+ def check_read_policy(context)
38
38
  if model.const_defined?("Policies") && model::Policies.respond_to?(:read)
39
39
  model::Policies.read(context)
40
40
  else
@@ -42,7 +42,7 @@ module Hai
42
42
  end
43
43
  end
44
44
 
45
- def check_list_policy
45
+ def check_list_policy(context)
46
46
  if model.const_defined?("Policies") && model::Policies.respond_to?(:list)
47
47
  model::Policies.list(context)
48
48
  else
data/lib/hai/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hai
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - basicbrogrammer