Module: Jat::Plugins::SimpleApi::ClassMethods

Defined in:
lib/jat/plugins/simple_api/simple_api.rb

Instance Method Summary collapse

Instance Method Details

#added_metaObject



100
101
102
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 100

def added_meta
  @added_meta ||= {}
end

#inherited(subclass) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 60

def inherited(subclass)
  super

  fields_parser_class = Class.new(self::FieldsParamParser)
  fields_parser_class.jat_class = subclass
  subclass.const_set(:FieldsParamParser, fields_parser_class)

  map_class = Class.new(self::Map)
  map_class.jat_class = subclass
  subclass.const_set(:Map, map_class)

  response_class = Class.new(self::Response)
  response_class.jat_class = subclass
  subclass.const_set(:Response, response_class)

  response_piece_class = Class.new(self::ResponsePiece)
  response_piece_class.jat_class = subclass
  subclass.const_set(:ResponsePiece, response_piece_class)

  # Assign same meta
  added_meta.each_value do |attribute|
    params = attribute.params
    subclass.meta(params[:name], **params[:opts], &params[:block])
  end
end

#map(context) ⇒ Object



109
110
111
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 109

def map(context)
  self::Map.call(context)
end

#map_exposedObject



117
118
119
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 117

def map_exposed
  @map_exposed ||= self::Map.call(exposed: :default)
end

#map_fullObject



113
114
115
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 113

def map_full
  @map_full ||= self::Map.call(exposed: :all)
end

#meta(name, **opts, &block) ⇒ Object



104
105
106
107
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 104

def meta(name, **opts, &block)
  new_attr = self::Attribute.new(name: name, opts: opts, block: block)
  added_meta[new_attr.name] = new_attr
end

#meta_key(new_meta_key) ⇒ Object



96
97
98
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 96

def meta_key(new_meta_key)
  config[:meta_key] = new_meta_key.to_sym
end

#root(default = nil, one: nil, many: nil) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 86

def root(default = nil, one: nil, many: nil)
  root_one = one || default
  root_many = many || default

  config[:root_one] = root_one ? root_one.to_sym : nil
  config[:root_many] = root_many ? root_many.to_sym : nil

  {root_one: root_one, root_many: root_many}
end