Class: Dao::Mode
- Inherits:
-
String
- Object
- String
- Dao::Mode
- Defined in:
- lib/dao/mode.rb
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #===(other) ⇒ Object
- #case_of?(other) ⇒ Boolean
-
#cases ⇒ Object
instance methods.
Class Method Details
.add(mode) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dao/mode.rb', line 17 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 |
.default ⇒ Object
34 35 36 |
# File 'lib/dao/mode.rb', line 34 def default @default ||= Mode.for(:read) end |
.for(mode) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/dao/mode.rb', line 6 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
13 14 15 |
# File 'lib/dao/mode.rb', line 13 def list @list ||= [] end |
Instance Method Details
#===(other) ⇒ Object
49 50 51 |
# File 'lib/dao/mode.rb', line 49 def ===(other) case_of?(other) end |
#case_of?(other) ⇒ Boolean
45 46 47 |
# File 'lib/dao/mode.rb', line 45 def case_of?(other) self == other or other.cases.include?(self) end |
#cases ⇒ Object
instance methods
41 42 43 |
# File 'lib/dao/mode.rb', line 41 def cases @cases ||= [] end |