recline 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/recline/appearance.rb +2 -1
- data/lib/recline/attribute_reflection.rb +3 -1
- data/lib/recline/model.rb +2 -0
- data/lib/recline/model_reflection.rb +2 -0
- data/lib/recline/types/attribute_reflection_type.rb +4 -3
- data/lib/recline/version.rb +1 -1
- data/lib/recline.rb +23 -12
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9861c39716e17c3dd5f127d7c2f4164a08f144d6
|
4
|
+
data.tar.gz: 5f6757a33cdc34d55b3e59ccbf90f78d6e514ad8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c59aa2cc8b37c549d4b75d2a34fe4ebcc9918e69ca6bf66480dad2cf1eae401a2d1d76595fcd1bb34ea1de93763cd509b5a323537ca5c0d9614adb805bd4fb
|
7
|
+
data.tar.gz: 6345aeaca86130e6d9822e63309a1d04e98248913810d73d13aec23fee3792f26e05a106aa49f137cd5f65a5812f24a638e5921e5439f88f3768c099f31889f8
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Recline
|
1
|
+
# Recline with Rails
|
2
2
|
Seamless form management for React using GraphQL.
|
3
3
|
|
4
4
|
**Work in progress.**
|
@@ -33,7 +33,7 @@ Recline.default_appearance_types = {
|
|
33
33
|
```
|
34
34
|
|
35
35
|
Help me explain this better:
|
36
|
-
[https://github.com/colepatrickturner/recline.rails/compare
|
36
|
+
[Create a Pull Request](https://github.com/colepatrickturner/recline.rails/compare)
|
37
37
|
|
38
38
|
# Installation
|
39
39
|
To begin, install the gem by adding it to the `Gemfile`:
|
@@ -45,7 +45,7 @@ To begin, install the gem by adding it to the `Gemfile`:
|
|
45
45
|
Add the following line to an object type that you would like to expose:
|
46
46
|
|
47
47
|
```ruby
|
48
|
-
implements
|
48
|
+
implements Recline::Model.interface, inherit: true
|
49
49
|
```
|
50
50
|
|
51
51
|
And that's it! This will add a `_model` field to your object type that will expose any field that can be mapped to an ActiveModel/ActiveRecord attribute.
|
data/lib/recline/appearance.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'graphql/rails/active_reflection/attribute_reflection'
|
2
|
+
|
1
3
|
class Recline::AttributeReflection < GraphQL::Rails::ActiveReflection::AttributeReflection
|
2
4
|
@schema_name = "ReclineAttribute"
|
3
5
|
attr_accessor :appearance
|
4
6
|
|
5
7
|
def initialize(field, klass, schema)
|
6
8
|
super
|
7
|
-
@appearance = Recline.appearance_for(klass, @name)
|
9
|
+
@appearance = Recline.appearance_for(field, klass, @name)
|
8
10
|
end
|
9
11
|
|
10
12
|
def primary_key?
|
data/lib/recline/model.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
require 'graphql/rails/active_reflection'
|
1
2
|
require 'graphql/rails/active_reflection/types/attribute_reflection_type'
|
2
3
|
Recline::Types::AttributeReflectionType = GraphQL::Rails::ActiveReflection::Types::AttributeReflectionType.redefine do
|
3
4
|
name "ReclineAttribute"
|
4
5
|
field :appearance, Recline::Types::AppearanceEnumType
|
6
|
+
field :createdAt, types.String, property: :created_at
|
7
|
+
field :updatedAt, types.String, property: :updated_at
|
5
8
|
|
6
9
|
field :read_only, types.Boolean do
|
7
10
|
resolve ->(obj, _args, _ctx) do
|
8
|
-
|
11
|
+
obj.primary_key?
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
12
|
-
|
13
|
-
puts "Recline::Types::AttributeReflectionType = #{Recline::Types::AttributeReflectionType}"
|
data/lib/recline/version.rb
CHANGED
data/lib/recline.rb
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
require 'graphql'
|
2
2
|
|
3
3
|
module Recline
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Types; end
|
5
|
+
|
6
|
+
def self.appearance_for(field, klass, name)
|
7
|
+
if field.metadata.key? :recline_appearance
|
8
|
+
return field.metadata[:recline_appearance]
|
7
9
|
else
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
field_type = field.type
|
11
|
+
while field_type.kind.wraps?
|
12
|
+
field_type = field_type.of_type
|
13
|
+
end
|
14
|
+
|
15
|
+
if default_appearance_types.key? field_type
|
16
|
+
default_appearance_types[field_type]
|
11
17
|
else
|
12
|
-
|
18
|
+
db_type = klass.type_for_attribute(name.to_s).type
|
19
|
+
if default_appearance_types.key? db_type
|
20
|
+
default_appearance_types[db_type]
|
21
|
+
else
|
22
|
+
fallback_appearance
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
@@ -24,12 +35,12 @@ module Recline
|
|
24
35
|
|
25
36
|
def default_appearance_types
|
26
37
|
@default_appearance_types ||= {
|
27
|
-
|
38
|
+
GraphQL::ID_TYPE => :string,
|
39
|
+
GraphQL::STRING_TYPE => :string,
|
40
|
+
GraphQL::INT_TYPE => :number,
|
41
|
+
GraphQL::FLOAT_TYPE => :number,
|
42
|
+
GraphQL::BOOLEAN_TYPE => :toggle,
|
28
43
|
text: :text,
|
29
|
-
integer: :number,
|
30
|
-
float: :number,
|
31
|
-
decimal: :number,
|
32
|
-
boolean: :toggle,
|
33
44
|
date: :date,
|
34
45
|
datetime: :datetime,
|
35
46
|
timestamp: :datetime
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cole Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: graphql-rails-activereflection
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.2.0
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.2.0
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.0'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: activerecord
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|