Module: Graphoid::Utils
- Defined in:
- lib/graphoid/utils.rb
Class Method Summary collapse
- .build_update_attributes(data, model, context) ⇒ Object
- .camelize(text) ⇒ Object
- .children_of(selection) ⇒ Object
- .first_children_of(selection) ⇒ Object
- .graphqlize(text) ⇒ Object
- .modelize(text) ⇒ Object
- .symbolize(fields) ⇒ Object
- .underscore(props, fields = []) ⇒ Object
Class Method Details
.build_update_attributes(data, model, context) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/graphoid/utils.rb', line 40 def build_update_attributes(data, model, context) user = context[:current_user] fields = Graphoid::Attribute.fieldnames_of(model) attrs = underscore(data, fields) attrs['updated_by_id'] = user.id if user && fields.include?('updated_by_id') attrs end |
.camelize(text) ⇒ Object
10 11 12 13 |
# File 'lib/graphoid/utils.rb', line 10 def camelize(text) # we are doing it twice because _id gets translated to Id the first time and to id the second time. graphqlize text.to_s.camelize(:lower).camelize(:lower) end |
.children_of(selection) ⇒ Object
23 24 25 |
# File 'lib/graphoid/utils.rb', line 23 def children_of(selection) selection.scoped_children.values.first end |
.first_children_of(selection) ⇒ Object
27 28 29 |
# File 'lib/graphoid/utils.rb', line 27 def first_children_of(selection) selection.scoped_children.values.first.values.first.scoped_children.values.first end |
.graphqlize(text) ⇒ Object
15 16 17 |
# File 'lib/graphoid/utils.rb', line 15 def graphqlize(text) text.to_s.gsub(/::/, '_') end |
.modelize(text) ⇒ Object
6 7 8 |
# File 'lib/graphoid/utils.rb', line 6 def modelize(text) graphqlize text.to_s.capitalize.camelize end |
.symbolize(fields) ⇒ Object
19 20 21 |
# File 'lib/graphoid/utils.rb', line 19 def symbolize(fields) fields.keys.map { |f| f.underscore.to_sym } end |
.underscore(props, fields = []) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/graphoid/utils.rb', line 31 def underscore(props, fields = []) attrs = {} props.each do |key, value| key = key.underscore if fields.exclude?(key) attrs[key] = value end attrs end |