Module: Anchor::Types

Defined in:
lib/anchor/walk.rb,
lib/anchor/types.rb

Defined Under Namespace

Modules: Inference Classes: Array, BigDecimal, Boolean, Enum, Float, Identity, Integer, Intersection, Literal, Maybe, NodeStream, Null, Object, Property, Record, Reference, Relationship, Resource, String, Union, Unknown, Walk

Class Method Summary collapse

Class Method Details

.camelize_without_inflection(val) ⇒ Object



262
263
264
265
266
267
268
269
# File 'lib/anchor/types.rb', line 262

def self.camelize_without_inflection(val)
  vals = val.split("_")
  if vals.length == 1
    vals[0]
  else
    ([vals[0]] + vals[1..].map(&:capitalize)).join("")
  end
end

.children(node) ⇒ Object



30
# File 'lib/anchor/types.rb', line 30

def children(node) = default_children(node)

.convert_case(value) ⇒ String

Parameters:

Returns:



273
274
275
276
277
278
279
280
281
# File 'lib/anchor/types.rb', line 273

def self.convert_case(value)
  case Anchor.config.field_case
  when :camel then value.to_s.underscore.camelize(:lower)
  when :camel_without_inflection then camelize_without_inflection(value.to_s.underscore)
  when :kebab then value.to_s.underscore.dasherize
  when :snake then value.to_s.underscore
  else value
  end
end

.default_children(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/anchor/types.rb', line 32

def default_children(node)
  case node
  when Anchor::Types::Array, Anchor::Types::Maybe, Anchor::Types::Identity then [node.type]
  when Anchor::Types::Union, Anchor::Types::Intersection then node.types
  when Anchor::Types::Record then [node.value_type]
  when Anchor::Types::Object then node.properties
  when Anchor::Types::Property then [node.type]
  else []
  end
end

.each_node(node) ⇒ Object



43
# File 'lib/anchor/types.rb', line 43

def each_node(node) = Anchor::Types::NodeStream.new(node)