Module: Alf::Rest::Helpers
- Extended by:
- Forwardable
- Defined in:
- lib/alf/rest/helpers.rb
Instance Method Summary collapse
- #alf_config ⇒ Object
- #assert!(msg = 'an assertion failed', status = nil, &bl) ⇒ Object
- #db_conn ⇒ Object
- #deny!(msg = 'an assertion failed', status = nil, &bl) ⇒ Object
- #fact!(msg = 'an assertion failed', status = nil, &bl) ⇒ Object
- #location_set? ⇒ Boolean
- #no_duplicate!(&bl) ⇒ Object
- #to_location(url, ids) ⇒ Object
- #with_db_conn {|db_conn| ... } ⇒ Object
Instance Method Details
#alf_config ⇒ Object
6 7 8 |
# File 'lib/alf/rest/helpers.rb', line 6 def alf_config env[Rest::RACK_CONFIG_KEY] end |
#assert!(msg = 'an assertion failed', status = nil, &bl) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/alf/rest/helpers.rb', line 33 def assert!(msg='an assertion failed', status=nil, &bl) db_conn.assert!(msg, &bl) rescue FactAssertionError => ex ex.http_error_status = status raise end |
#db_conn ⇒ Object
10 11 12 |
# File 'lib/alf/rest/helpers.rb', line 10 def db_conn alf_config.connection end |
#deny!(msg = 'an assertion failed', status = nil, &bl) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/alf/rest/helpers.rb', line 40 def deny!(msg='an assertion failed', status=nil, &bl) db_conn.deny!(msg, &bl) rescue FactAssertionError => ex ex.http_error_status = status raise end |
#fact!(msg = 'an assertion failed', status = nil, &bl) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/alf/rest/helpers.rb', line 47 def fact!(msg='an assertion failed', status=nil, &bl) db_conn.fact!(msg, &bl) rescue FactAssertionError => ex ex.http_error_status = status raise end |
#location_set? ⇒ Boolean
29 30 31 |
# File 'lib/alf/rest/helpers.rb', line 29 def location_set? response.headers["Location"] end |
#no_duplicate!(&bl) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/alf/rest/helpers.rb', line 54 def no_duplicate!(&bl) found = relvar(&bl) unless found.empty? ids = found.project(found.keys.first.to_attr_list) halt Alf::Rest::Response.new(env){|r| r.status = 200 r.body = {'status' => 'success', 'message' => 'skipped'} r["Location"] = to_location(request.path, ids) }.finish end end |
#to_location(url, ids) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/alf/rest/helpers.rb', line 22 def to_location(url, ids) ids = ids.matching_relation if ids.respond_to?(:matching_relation) ids = ids.tuple_extract if ids.respond_to?(:tuple_extract) ids = ids.to_hash.values "#{url}/#{ids.join(',')}" end |
#with_db_conn {|db_conn| ... } ⇒ Object
14 15 16 |
# File 'lib/alf/rest/helpers.rb', line 14 def with_db_conn yield(db_conn) end |