Class: Cda::MetaInfo::Field

Inherits:
Virtus::Attribute
  • Object
show all
Defined in:
lib/cda/meta_info.rb

Instance Method Summary collapse

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/cda/meta_info.rb', line 55

def allowed?
  !prohibited?
end

#build_methodObject



77
78
79
# File 'lib/cda/meta_info.rb', line 77

def build_method
  annotations[:build_method]
end

#collection?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/cda/meta_info.rb', line 67

def collection?
  type.respond_to?(:member_type)
end

#complex?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/cda/meta_info.rb', line 51

def complex?
  model_class.respond_to?(:attribute_set)
end

#element_nameObject



71
72
73
74
75
# File 'lib/cda/meta_info.rb', line 71

def element_name
  @element_name ||= begin
    sanitize_element_name(model_class.respond_to?(:template_type) ? model_class.template_type : name)
  end
end

#fully_qualified_nameObject



33
34
35
36
37
# File 'lib/cda/meta_info.rb', line 33

def fully_qualified_name
  sanitized_name = sanitize_element_name(name)
  ns = annotations[:ns]
  !ns.nil? ? "#{ns}:#{sanitized_name}" : sanitized_name
end

#get_value(instance) ⇒ Object



39
40
41
# File 'lib/cda/meta_info.rb', line 39

def get_value(instance)
  instance.send(name)
end

#kindObject



63
64
65
# File 'lib/cda/meta_info.rb', line 63

def kind
  annotations.fetch(:kind, :element)
end

#model_classObject



47
48
49
# File 'lib/cda/meta_info.rb', line 47

def model_class
  respond_to?(:member_type) ? member_type.primitive : type.primitive
end

#new_instanceObject



88
89
90
# File 'lib/cda/meta_info.rb', line 88

def new_instance
  type.primitive.new
end

#prohibited?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cda/meta_info.rb', line 59

def prohibited?
  annotations[:use] == :prohibited
end

#set_value(instance, value) ⇒ Object



43
44
45
# File 'lib/cda/meta_info.rb', line 43

def set_value(instance, value)
  instance.send("#{name}=", value)
end

#wrapper_element_nameObject



81
82
83
84
85
86
# File 'lib/cda/meta_info.rb', line 81

def wrapper_element_name
  @wrapper_element_name ||= begin
    name, _ = annotations[:wrap_with]
    sanitize_element_name(name)
  end
end