Module: Jat::Plugins::SimpleApi::ClassMethods
- Defined in:
- lib/jat/plugins/simple_api/simple_api.rb
Instance Method Summary collapse
- #added_meta ⇒ Object
- #inherited(subclass) ⇒ Object
- #map(context) ⇒ Object
- #map_exposed ⇒ Object
- #map_full ⇒ Object
- #meta(name, **opts, &block) ⇒ Object
- #meta_key(new_meta_key) ⇒ Object
- #root(default = nil, one: nil, many: nil) ⇒ Object
Instance Method Details
#added_meta ⇒ Object
100 101 102 |
# File 'lib/jat/plugins/simple_api/simple_api.rb', line 100 def @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 .each_value do |attribute| params = attribute.params subclass.(params[:name], **params[:opts], ¶ms[: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_exposed ⇒ Object
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_full ⇒ Object
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 (name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) [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 () config[: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 |