Class: RestfulSpec::Specification::SmartSelect

Inherits:
Array
  • Object
show all
Defined in:
lib/restful_spec/specification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ SmartSelect

Returns a new instance of SmartSelect.



158
159
160
161
162
# File 'lib/restful_spec/specification.rb', line 158

def initialize(*args, &block)
  @options = args.extract_options!
  super(args.first.to_a)
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



152
153
154
# File 'lib/restful_spec/specification.rb', line 152

def options
  @options
end

Instance Method Details

#_included_(matcher) ⇒ Object



154
155
156
# File 'lib/restful_spec/specification.rb', line 154

def _included_(matcher)
  ->(item) { Array.wrap(options[matcher]).include?(item) }
end

#add(matcher) ⇒ Object



164
165
166
# File 'lib/restful_spec/specification.rb', line 164

def add(matcher)
  self.replace self + Array.wrap(options[matcher])
end

#reject(matcher) ⇒ Object Also known as: reject!



174
175
176
# File 'lib/restful_spec/specification.rb', line 174

def reject(matcher)
  self.replace( super &_included_(matcher) ) if options[matcher].present?
end

#select(matcher) ⇒ Object Also known as: select!



168
169
170
# File 'lib/restful_spec/specification.rb', line 168

def select(matcher)
  self.replace( super &_included_(matcher) ) if options[matcher].present?
end