Class: XDry::OClass

Inherits:
Object
  • Object
show all
Defined in:
lib/xdry/parsing/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oglobal, name) ⇒ OClass

Returns a new instance of OClass.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/xdry/parsing/model.rb', line 40

def initialize oglobal, name
  @oglobal, @name = oglobal, name

  @names_to_attributes = {}
  @attributes = []

  @selectors_to_methods = {}
  @methods = []

  @field_defs = []
  @property_defs = []
  @interfaces = []
  @implementations = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



36
37
38
# File 'lib/xdry/parsing/model.rb', line 36

def attributes
  @attributes
end

#field_defsObject (readonly)

Returns the value of attribute field_defs.



36
37
38
# File 'lib/xdry/parsing/model.rb', line 36

def field_defs
  @field_defs
end

#implementationsObject (readonly)

Returns the value of attribute implementations.



38
39
40
# File 'lib/xdry/parsing/model.rb', line 38

def implementations
  @implementations
end

#interfacesObject (readonly)

Returns the value of attribute interfaces.



37
38
39
# File 'lib/xdry/parsing/model.rb', line 37

def interfaces
  @interfaces
end

#methodsObject (readonly)

Returns the value of attribute methods.



36
37
38
# File 'lib/xdry/parsing/model.rb', line 36

def methods
  @methods
end

#nameObject (readonly)

Returns the value of attribute name.



36
37
38
# File 'lib/xdry/parsing/model.rb', line 36

def name
  @name
end

#oglobalObject (readonly)

Returns the value of attribute oglobal.



35
36
37
# File 'lib/xdry/parsing/model.rb', line 35

def oglobal
  @oglobal
end

Instance Method Details

#<<(node) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/xdry/parsing/model.rb', line 73

def << node
  case node
  when NFieldDef
    @field_defs << node
    attr_name = node.name.gsub /^_/, ''
    lookup_attribute(attr_name).add_field_def! node
  when NPropertyDef
    @property_defs << node
    attr_name = node.name
    lookup_attribute(attr_name).add_property_def! node
  when NMethodHeader
    selector = node.selector
    lookup_method(selector).add_method_header! node
  when NSynthesize
    node.items.each do |item|
      lookup_attribute(item.property_name).add_synthesize! node
    end
  when SInterfaceFields
    node.bind(self)
  when SMethodImpl
    lookup_method(node.selector).add_method_impl! node
  end
end

#add_implementation(child) ⇒ Object



59
60
61
# File 'lib/xdry/parsing/model.rb', line 59

def add_implementation child
  @implementations << child.bind(self)
end

#add_interface(child) ⇒ Object



55
56
57
# File 'lib/xdry/parsing/model.rb', line 55

def add_interface child
  @interfaces << child.bind(self)
end

#find_attribute(name) ⇒ Object



101
102
103
# File 'lib/xdry/parsing/model.rb', line 101

def find_attribute name
  @names_to_attributes[name]
end

#find_method(selector) ⇒ Object



105
106
107
# File 'lib/xdry/parsing/model.rb', line 105

def find_method selector
  @selectors_to_methods[selector]
end

#has_method_impl?(selector) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/xdry/parsing/model.rb', line 109

def has_method_impl? selector
  m = find_method(selector)
  return m && m.has_impl?
end

#main_implementationObject



68
69
70
71
# File 'lib/xdry/parsing/model.rb', line 68

def main_implementation
  # FIXME
  @implementations.first
end

#main_interfaceObject



63
64
65
66
# File 'lib/xdry/parsing/model.rb', line 63

def main_interface
  # FIXME
  @interfaces.first
end

#to_sObject



97
98
99
# File 'lib/xdry/parsing/model.rb', line 97

def to_s
  "class #{name}"
end