Module: Graphoid::Utils
- Defined in:
- lib/graphoid/utils.rb
Class Method Summary collapse
- .build_update_attributes(data, model, context) ⇒ Object
- .camelize(text) ⇒ Object
- .graphqlize(text) ⇒ Object
- .modelize(text) ⇒ Object
- .symbolize(fields) ⇒ Object
- .underscore(props, fields = []) ⇒ Object
Class Method Details
.build_update_attributes(data, model, context) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/graphoid/utils.rb', line 30 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
8 9 10 11 |
# File 'lib/graphoid/utils.rb', line 8 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 |
.graphqlize(text) ⇒ Object
13 14 15 |
# File 'lib/graphoid/utils.rb', line 13 def graphqlize text text.to_s.gsub(/::/, '_') end |
.modelize(text) ⇒ Object
4 5 6 |
# File 'lib/graphoid/utils.rb', line 4 def modelize text graphqlize text.to_s.capitalize.camelize end |
.symbolize(fields) ⇒ Object
17 18 19 |
# File 'lib/graphoid/utils.rb', line 17 def symbolize(fields) fields.keys.map(&:underscore).map(&:to_sym) end |
.underscore(props, fields = []) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/graphoid/utils.rb', line 21 def underscore props, fields = [] attrs = {} props.each do |key, value| key = key.underscore if fields.exclude?(key) attrs[key] = value end attrs end |