Class: XDry::NPropertyDef

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

Instance Attribute Summary collapse

Attributes inherited from Node

#indent, #pos

Instance Method Summary collapse

Methods inherited from Node

#method_missing, #tagged_with?, #tags, #tags=, #tags_comment

Constructor Details

#initialize(name, type) ⇒ NPropertyDef

Returns a new instance of NPropertyDef.

Raises:

  • (StandardError)


73
74
75
76
77
# File 'lib/xdry/parsing/nodes.rb', line 73

def initialize name, type
  super()
  raise StandardError, "type cannot be nil for prop #{name}" if type.nil?
  @name, @type = name, type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class XDry::Node

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



71
72
73
# File 'lib/xdry/parsing/nodes.rb', line 71

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



71
72
73
# File 'lib/xdry/parsing/nodes.rb', line 71

def type
  @type
end

Instance Method Details

#outlet?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/xdry/parsing/nodes.rb', line 79

def outlet?
  tagged_with? 'outlet'
end

#to_sObject



83
84
85
# File 'lib/xdry/parsing/nodes.rb', line 83

def to_s
  "#{if outlet? then 'IBOutlet ' else '' end}#{@type} #{@name}"
end

#to_sourceObject



87
88
89
90
91
92
93
94
# File 'lib/xdry/parsing/nodes.rb', line 87

def to_source
  retainment = case @type.default_property_retainment_policy
    when '' then ''
    else ', ' + @type.default_property_retainment_policy
  end
  iboutlet = if outlet? then "IBOutlet " else '' end
  "@property(nonatomic#{retainment}) #{iboutlet}#{@type.to_source_with_space}#{@name};"
end