File: basic_api.rb

package info (click to toggle)
ruby-librarian 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 624 kB
  • sloc: ruby: 6,109; makefile: 11
file content (45 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Librarian
  module Source
    module BasicApi

      def self.included(base)
        base.extend ClassMethods
        class << base
          def lock_name(name)
            def_sclass_prop(:lock_name, name)
          end

          def spec_options(keys)
            def_sclass_prop(:spec_options, keys)
          end

        private

          def def_sclass_prop(name, arg)
            sclass = class << self ; self ; end
            sclass.module_exec do
              remove_method(name)
              define_method(name) { arg }
            end
          end
        end
      end

      module ClassMethods
        def from_lock_options(environment, options)
          new(environment, options[:remote], options.reject{|k, v| k == :remote})
        end

        def from_spec_args(environment, param, options)
          recognized_options = spec_options
          unrecognized_options = options.keys - recognized_options
          unrecognized_options.empty? or raise Error,
            "unrecognized options: #{unrecognized_options.join(", ")}"

          new(environment, param, options)
        end
      end

    end
  end
end