Class: Yao::Resources::Dumper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yao/resources/dumper/base.rb

Class Method Summary collapse

Class Method Details

.bug_fields=(v) ⇒ Object



8
9
10
# File 'lib/yao/resources/dumper/base.rb', line 8

def self.bug_fields=(v)
  @bug_fields = v
end

.dump(obj) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yao/resources/dumper/base.rb', line 12

def self.dump(obj)
  [obj].flatten.map do |o|
    arr = @fields.map{|field|
      # bugfixされるまで特定のメソッドは `_id` をつける
      if [@bug_fields].flatten.include?(field)
        name = field + "_id"
        [name, o.send("[]", name)]
      else
        result = o.send(field)

        result = if result.instance_of?(Array)
                  result.map{|r| resource_dump(r)}
                else
                  resource_dump(result)
                end

        [field, result]
      end
    }.flatten(1)

    Hash[*arr]
  end
end

.fields=(v) ⇒ Object



4
5
6
# File 'lib/yao/resources/dumper/base.rb', line 4

def self.fields=(v)
  @fields = v
end