Module: Musa::Series::Serie::Prototyping

Defined in:
lib/musa-dsl/series/base-series.rb

Defined Under Namespace

Classes: PrototypingError

Instance Method Summary collapse

Instance Method Details

#defined?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/musa-dsl/series/base-series.rb', line 154

def defined?
  !undefined?
end

#instanceObject Also known as: i



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/musa-dsl/series/base-series.rb', line 175

def instance
  try_to_resolve_undefined_state_if_needed

  if instance?
    self
  elsif prototype?
    new_instance = clone

    new_instance._instance!
    new_instance.mark_as_instance!(self)
    new_instance.init if new_instance.respond_to?(:init)

    new_instance
  else
    raise PrototypingError, 'Can\'t get an instance of an undefined serie'
  end
end

#instance?Boolean

Returns:

  • (Boolean)


144
145
146
147
# File 'lib/musa-dsl/series/base-series.rb', line 144

def instance?
  try_to_resolve_undefined_state_if_needed
  @state&.==(:instance)
end

#prototypeObject Also known as: p



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/musa-dsl/series/base-series.rb', line 158

def prototype
  try_to_resolve_undefined_state_if_needed

  if prototype?
    self
  elsif instance?
    # if the series has been directly created as an instance (i.e., because is an operation over an instance)
    # the prototype doesn't exist.
    #
    @instance_of
  else
    raise PrototypingError, 'Can\'t get the prototype of an undefined serie'
  end
end

#prototype?Boolean

Returns:

  • (Boolean)


139
140
141
142
# File 'lib/musa-dsl/series/base-series.rb', line 139

def prototype?
  try_to_resolve_undefined_state_if_needed
  @state&.==(:prototype)
end

#stateObject



134
135
136
137
# File 'lib/musa-dsl/series/base-series.rb', line 134

def state
  try_to_resolve_undefined_state_if_needed
  @state || :undefined
end

#undefined?Boolean

Returns:

  • (Boolean)


149
150
151
152
# File 'lib/musa-dsl/series/base-series.rb', line 149

def undefined?
  try_to_resolve_undefined_state_if_needed
  @state.nil? || @state == :undefined
end