graphql-rails-activereflection 0.1.2 → 0.2.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: a81c1a5d660000185c3ed8b045308b24c0281982
4
- data.tar.gz: fc4b2c58c1c69f13e64ec79ec0707ff0f35a2d77
3
+ metadata.gz: 65192372c0519732bbd4feadef4c4680779af4a3
4
+ data.tar.gz: 201df139d12a889ed72173a80ee6b30eb80925a9
5
5
  SHA512:
6
- metadata.gz: 9a52d0ba5587ce4af06e4cd7d1e3c656d64319e3eb2613009919e750403fb482fdaa08f394edb6b8a9eb5cce4063ee76738ab1f9cd35bb86c1b69af9b0a064d0
7
- data.tar.gz: fcdd14e32bc65f505330aa30e5332d22fb46edf5ba9db87bb2c81efdb730a014947c767a510c258e4555df54ec94d0cd50720641a522e6f5d2c41d8ec20e8fa7
6
+ metadata.gz: 27a4d364ff9f6f62f71ce79431b3ba07635272a5f1a700417ab75b025addedfd5fdb7b8e34c487d7286b2d34439cee24bf673c178643cf6214e9477c7b217a20
7
+ data.tar.gz: 506863916e7cd22ff57f33e6c7d8ff8d0742d509e096f9072a1c1719a6ef9bc6e561511087e521ba4e649decf647cca5e30e2ebb47e9fcfa343ab0cfc162e6c8
@@ -3,3 +3,7 @@
3
3
 
4
4
  ### Version 0.1.0
5
5
  Initial commit. More to come.
6
+
7
+ ### Version 0.2.0
8
+ Added ModelReflection.get_attributes and ModelReflection.include_property?
9
+ Added AttributeReflection.get_validators and ActiveReflection.include_validator?
data/README.md CHANGED
@@ -28,12 +28,12 @@ And that's it! This will add a `_model` field to the object type and enables the
28
28
 
29
29
  ```graphql
30
30
  fragment on YourObjectType {
31
- _model {
32
- attributes {
31
+ _model: ActiveReflectionModel {
32
+ attributes: [ActiveReflectionAttribute] {
33
33
  name: String
34
34
  field_name: String
35
35
 
36
- validators {
36
+ validators: [ActiveReflectionValidator] {
37
37
  absence: Boolean
38
38
  presence: Boolean
39
39
  uniqueness: Boolean
@@ -45,7 +45,7 @@ fragment on YourObjectType {
45
45
  exclusion: [String]
46
46
  }
47
47
 
48
- validate(int: Integer, str: String, float: Float, bool: Boolean) {
48
+ validate(int: Integer, str: String, float: Float, bool: Boolean): ActiveReflectionValidation {
49
49
  valid: Boolean
50
50
  errors: [String]
51
51
  }
@@ -12,17 +12,27 @@ module GraphQL::Rails::ActiveReflection
12
12
  @klass = klass
13
13
  @field_name = field.name
14
14
  @name = field.property || field.name
15
- @validators = klass.validators.map { |validator|
15
+ @errors = []
16
+ get_validators
17
+ end
18
+
19
+ class << self
20
+ attr_accessor :schema_name
21
+ end
22
+
23
+ protected
24
+
25
+ def get_validators
26
+ @validators ||= klass.validators.map { |validator|
16
27
  # Skip if the validator does not apply to this field
17
28
  # Skip if there are :if or :unless options (conditionals purposely unsupported)
18
- next if validator.attributes.exclude?(@name.to_sym) || validator.options[:if].present? || validator.options[:unless].present?
29
+ next unless include_validator? validator
19
30
  GraphQL::Rails::ActiveReflection::ValidatorReflection.new(validator)
20
31
  }.compact
21
- @errors = []
22
32
  end
23
33
 
24
- class << self
25
- attr_accessor :schema_name
34
+ def include_validator? validator
35
+ validator.attributes.include?(@name.to_sym) && validator.options[:if].nil? && validator.options[:unless].nil?
26
36
  end
27
37
  end
28
38
  end
@@ -1,11 +1,11 @@
1
1
  module GraphQL::Rails::ActiveReflection
2
2
  class ModelReflection
3
3
  @schema_name = "ActiveReflectionModel"
4
- @reflections = {}
4
+ @@reflections = {}
5
5
 
6
6
  def self.call(obj, args, ctx)
7
7
  raise TypeError, "ActiveReflection object type must be derived from ActiveRecord::Base" unless obj.is_a?(ActiveRecord::Base)
8
- @reflections[obj] ||= new(obj, ctx)
8
+ @@reflections[obj] ||= new(obj, ctx)
9
9
  end
10
10
 
11
11
  attr_reader :attributes
@@ -14,17 +14,26 @@ module GraphQL::Rails::ActiveReflection
14
14
  @klass = obj.class
15
15
  @type = ctx.schema.resolve_type(obj, ctx)
16
16
  @schema = ctx.schema
17
- @attributes = @type.fields.map { |name, field|
17
+ get_attributes
18
+ end
19
+
20
+ class << self
21
+ attr_accessor :schema_name
22
+ end
23
+
24
+ protected
25
+ def get_attributes
26
+ @attributes ||= @type.fields.map { |name, field|
18
27
  # No reflection if it's not a model attribute
19
28
  property = field.property || name
20
- if @klass.attribute_names.include? property
29
+ if include_property? property
21
30
  GraphQL::Rails::ActiveReflection::AttributeReflection.new(field, @klass, @schema)
22
31
  end
23
32
  }.compact
24
33
  end
25
34
 
26
- class << self
27
- attr_accessor :schema_name
35
+ def include_property? name
36
+ @klass.attribute_names.include? name
28
37
  end
29
38
 
30
39
  end
@@ -1,7 +1,7 @@
1
1
  module GraphQL
2
2
  module Rails
3
3
  module ActiveReflection
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-rails-activereflection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
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-04-19 00:00:00.000000000 Z
11
+ date: 2017-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -37,7 +37,7 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
- type: :development
40
+ type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
@@ -51,7 +51,7 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- type: :development
54
+ type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements: