Class: Panko::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/panko/attribute.rb,
ext/panko_serializer/serialization_descriptor/attribute.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(name, alias_name: nil) ⇒ Object



5
6
7
8
# File 'lib/panko/attribute.rb', line 5

def self.create(name, alias_name: nil)
  alias_name = alias_name.to_s unless alias_name.nil?
  Attribute.new(name.to_s, alias_name)
end

.new(*args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'ext/panko_serializer/serialization_descriptor/attribute.c', line 28

static VALUE attribute_new(int argc, VALUE* argv, VALUE self) {
  Attribute attribute;

  Check_Type(argv[0], T_STRING);
  if (argv[1] != Qnil) {
    Check_Type(argv[1], T_STRING);
  }

  attribute = ALLOC(struct _Attribute);
  attribute->name_str = argv[0];
  attribute->name_id = rb_intern_str(attribute->name_str);
  attribute->alias_name = argv[1];
  attribute->type = Qnil;
  attribute->record_class = Qnil;

  return Data_Wrap_Struct(cAttribute, attribute_mark, attribute_free,
                          attribute);
}

Instance Method Details

#==(other) ⇒ Object



10
11
12
13
14
15
# File 'lib/panko/attribute.rb', line 10

def ==(other)
  return name.to_sym == other if other.is_a? Symbol
  return name == other.name && alias_name == other.alias_name if other.is_a? Panko::Attribute

  super
end

#alias_nameObject



80
81
82
83
# File 'ext/panko_serializer/serialization_descriptor/attribute.c', line 80

VALUE attribute_alias_name_ref(VALUE self) {
  Attribute attribute = (Attribute)DATA_PTR(self);
  return attribute->alias_name;
}

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/panko/attribute.rb', line 21

def eql?(other)
  self.==(other)
end

#hashObject



17
18
19
# File 'lib/panko/attribute.rb', line 17

def hash
  name.to_sym.hash
end

#inspectObject



25
26
27
# File 'lib/panko/attribute.rb', line 25

def inspect
  "<Panko::Attribute name=#{name.inspect} alias_name=#{alias_name.inspect}>"
end

#nameObject



75
76
77
78
# File 'ext/panko_serializer/serialization_descriptor/attribute.c', line 75

VALUE attribute_name_ref(VALUE self) {
  Attribute attribute = (Attribute)DATA_PTR(self);
  return attribute->name_str;
}