Module: Ambition::API
Instance Method Summary collapse
- #all?(&block) ⇒ Boolean
- #ambition_adapter ⇒ Object
- #ambition_adapter=(klass) ⇒ Object
-
#ambition_context ⇒ Object
Plumbing.
- #ambition_owner ⇒ Object
- #any?(&block) ⇒ Boolean
-
#detect(&block) ⇒ Object
Convenience methods.
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #entries ⇒ Object (also: #to_a)
- #first(count = 1) ⇒ Object
-
#select(&block) ⇒ Object
Entry methods.
- #size ⇒ Object
- #slice(start, length = nil) ⇒ Object (also: #[])
- #sort_by(&block) ⇒ Object
Instance Method Details
#all?(&block) ⇒ Boolean
51 52 53 |
# File 'lib/ambition/api.rb', line 51 def all?(&block) size == select(&block).size end |
#ambition_adapter ⇒ Object
65 66 67 68 69 |
# File 'lib/ambition/api.rb', line 65 def ambition_adapter name = respond_to?(:name) ? name : self.class.name parent = respond_to?(:superclass) ? superclass : self.class.superclass @@ambition_adapter[name] || @@ambition_adapter[parent.name] end |
#ambition_adapter=(klass) ⇒ Object
71 72 73 74 |
# File 'lib/ambition/api.rb', line 71 def ambition_adapter=(klass) @@ambition_adapter ||= {} @@ambition_adapter[name] = klass end |
#ambition_context ⇒ Object
Plumbing
61 62 63 |
# File 'lib/ambition/api.rb', line 61 def ambition_context Context.new(self) end |
#ambition_owner ⇒ Object
76 77 78 |
# File 'lib/ambition/api.rb', line 76 def ambition_owner @owner || self end |
#any?(&block) ⇒ Boolean
47 48 49 |
# File 'lib/ambition/api.rb', line 47 def any?(&block) select(&block).size > 0 end |
#detect(&block) ⇒ Object
Convenience methods
34 35 36 |
# File 'lib/ambition/api.rb', line 34 def detect(&block) select(&block).first end |
#each(&block) ⇒ Object
43 44 45 |
# File 'lib/ambition/api.rb', line 43 def each(&block) entries.each(&block) end |
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/ambition/api.rb', line 55 def empty? size.zero? end |
#entries ⇒ Object Also known as: to_a
17 18 19 |
# File 'lib/ambition/api.rb', line 17 def entries ambition_context.kick end |
#first(count = 1) ⇒ Object
38 39 40 41 |
# File 'lib/ambition/api.rb', line 38 def first(count = 1) sliced = slice(0, count) count == 1 ? Array(sliced.kick).first : sliced end |
#select(&block) ⇒ Object
Entry methods
7 8 9 10 |
# File 'lib/ambition/api.rb', line 7 def select(&block) context = ambition_context context << Processors::Select.new(context, block) end |
#size ⇒ Object
22 23 24 |
# File 'lib/ambition/api.rb', line 22 def size ambition_context.size end |
#slice(start, length = nil) ⇒ Object Also known as: []
26 27 28 29 |
# File 'lib/ambition/api.rb', line 26 def slice(start, length = nil) context = ambition_context context << Processors::Slice.new(context, start, length) end |
#sort_by(&block) ⇒ Object
12 13 14 15 |
# File 'lib/ambition/api.rb', line 12 def sort_by(&block) context = ambition_context context << Processors::Sort.new(context, block) end |