Class: Sinatra::Rabbit::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/rabbit/features.rb

Defined Under Namespace

Classes: Operation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}, &block) ⇒ Feature



26
27
28
29
30
31
32
33
# File 'lib/sinatra/rabbit/features.rb', line 26

def initialize(name, opts={}, &block)
  @name = name
  @operations = []
  @collection = opts[:for]
  @constraints = {}
  raise "Each feature must define collection for which it will be valid using :for parameter" unless @collection
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection



22
23
24
# File 'lib/sinatra/rabbit/features.rb', line 22

def collection
  @collection
end

#constraintsObject (readonly)

Returns the value of attribute constraints



24
25
26
# File 'lib/sinatra/rabbit/features.rb', line 24

def constraints
  @constraints
end

#description(s = nil) ⇒ Object (readonly)

Returns the value of attribute description



21
22
23
# File 'lib/sinatra/rabbit/features.rb', line 21

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name



20
21
22
# File 'lib/sinatra/rabbit/features.rb', line 20

def name
  @name
end

#operationsObject (readonly)

Returns the value of attribute operations



23
24
25
# File 'lib/sinatra/rabbit/features.rb', line 23

def operations
  @operations
end

Instance Method Details

#constraint(name, value) ⇒ Object



44
45
46
# File 'lib/sinatra/rabbit/features.rb', line 44

def constraint(name, value)
  @constraints[name] = value
end

#operation(name, &block) ⇒ Object



35
36
37
38
# File 'lib/sinatra/rabbit/features.rb', line 35

def operation(name, &block)
  @operations << Operation.new(name, &block) if block_given?
  @operations.find { |o| o.name == name }
end