Module: FTL::Serializer::DSL

Includes:
Format
Included in:
Base
Defined in:
lib/ftl/serializer/dsl.rb,
lib/ftl/serializer/dsl/format.rb

Defined Under Namespace

Modules: Format

Instance Attribute Summary collapse

Attributes included from Format

#root_name

Instance Method Summary collapse

Methods included from Format

#camel_case?, #format, #hash_format, #root

Instance Attribute Details

#attribute_listObject (readonly)

Returns the value of attribute attribute_list.



9
10
11
# File 'lib/ftl/serializer/dsl.rb', line 9

def attribute_list
  @attribute_list
end

#object_mergeObject (readonly)

Returns the value of attribute object_merge.



9
10
11
# File 'lib/ftl/serializer/dsl.rb', line 9

def object_merge
  @object_merge
end

Instance Method Details

#attributes(*attrs) ⇒ Object



27
28
29
# File 'lib/ftl/serializer/dsl.rb', line 27

def attributes(*attrs)
  attribute_list.push(attrs).flatten!.uniq!
end

#define_to_hObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ftl/serializer/dsl.rb', line 35

def define_to_h
  class_eval "    def hashify\n      hash = {\n        \#{\n          attribute_list.reduce('') do |method_str, attr|\n            if self.camel_case?\n              attr_name = attr.to_s.camelize(:lower)\n            else\n              attr_name = attr\n            end\n\n            if instance_methods.include?(attr)\n              method_str + \"\\\"\#{attr_name}\\\" => \#{attr},\"\n            else\n              method_str + \"\\\"\#{attr_name}\\\" => obj.\#{attr},\"\n            end\n          end\n        }\n      }\n\n      merge!(hash)\n    end\n  METHOD\nend\n", __FILE__, __LINE__ + 1

#inherited(child) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ftl/serializer/dsl.rb', line 11

def inherited(child)
  child.attributes(attribute_list) unless attribute_list.nil?
  child.merge_with(object_merge) unless object_merge.nil?
  child.root(root_name)

  FTL::Serializer.register_serializer(child)
end

#merge_with(*attrs) ⇒ Object



31
32
33
# File 'lib/ftl/serializer/dsl.rb', line 31

def merge_with(*attrs)
  object_merge.push(attrs).flatten!.uniq!
end