Class: Dao::Mode
- Inherits:
-
String
- Object
- String
- Dao::Mode
- Defined in:
- lib/dao/mode.rb
Constant Summary collapse
- HTTP =
setup mode singletons and their aliases
( READ = %w[ get options head ] ) + ( WRITE = %w[ post put delete trace connect ] )
Class Method Summary collapse
Instance Method Summary collapse
- #===(other) ⇒ Object
-
#aliases ⇒ Object
instance methods.
- #case_of?(other) ⇒ Boolean
Class Method Details
.add(mode) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dao/mode.rb', line 18 def add(mode) mode = new(mode.to_s) unless list.include?(mode) list.push(mode) singleton_class = class << Mode self end singleton_class.module_eval do attr_accessor mode end Mode.send("#{ mode }=", mode) mode end end |
.alias(a, b) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/dao/mode.rb', line 46 def Mode.alias(a, b) a, b = Mode.for(a), Mode.for(b) a.aliases.push(b) unless a.aliases.include?(b) b.aliases.push(a) unless b.aliases.include?(a) (a.aliases + b.aliases).uniq end |
.default ⇒ Object
35 36 37 |
# File 'lib/dao/mode.rb', line 35 def default @default ||= Mode.for(:read) end |
.for(mode) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/dao/mode.rb', line 7 def for(mode) return mode if mode.is_a?(Mode) mode = mode.to_s return Mode.send(mode) if Mode.respond_to?(mode) Mode.new(mode) end |
.list ⇒ Object
14 15 16 |
# File 'lib/dao/mode.rb', line 14 def list @list ||= [] end |
Instance Method Details
#===(other) ⇒ Object
58 59 60 |
# File 'lib/dao/mode.rb', line 58 def ===(other) case_of?(other) end |
#aliases ⇒ Object
instance methods
42 43 44 |
# File 'lib/dao/mode.rb', line 42 def aliases @aliases ||= [] end |