Class: Calamum::DocParser
- Inherits:
-
Object
- Object
- Calamum::DocParser
- Defined in:
- lib/calamum/doc_parser.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#resources ⇒ Object
Returns the value of attribute resources.
Instance Method Summary collapse
- #get_authentication ⇒ Object
- #get_description ⇒ Object
- #get_errors ⇒ Object
- #get_name ⇒ Object
- #get_resources ⇒ Object
- #get_seperate_resources ⇒ Object
- #get_url ⇒ Object
- #get_version ⇒ Object
-
#initialize(definition) ⇒ DocParser
constructor
A new instance of DocParser.
- #load_resources ⇒ Object
- #validate_resource?(resource) ⇒ Boolean
Constructor Details
#initialize(definition) ⇒ DocParser
Returns a new instance of DocParser.
4 5 6 7 |
# File 'lib/calamum/doc_parser.rb', line 4 def initialize(definition) @resources = Hash.new @definition = definition end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
2 3 4 |
# File 'lib/calamum/doc_parser.rb', line 2 def definition @definition end |
#resources ⇒ Object
Returns the value of attribute resources.
2 3 4 |
# File 'lib/calamum/doc_parser.rb', line 2 def resources @resources end |
Instance Method Details
#get_authentication ⇒ Object
21 22 23 |
# File 'lib/calamum/doc_parser.rb', line 21 def get_authentication @definition['authentication'] end |
#get_description ⇒ Object
25 26 27 |
# File 'lib/calamum/doc_parser.rb', line 25 def get_description @definition['description'] end |
#get_errors ⇒ Object
29 30 31 |
# File 'lib/calamum/doc_parser.rb', line 29 def get_errors @definition['errors'] end |
#get_name ⇒ Object
13 14 15 |
# File 'lib/calamum/doc_parser.rb', line 13 def get_name @definition['name'] end |
#get_resources ⇒ Object
33 34 35 36 |
# File 'lib/calamum/doc_parser.rb', line 33 def get_resources resources = @definition['resources'].kind_of?(String) ? get_seperate_resources : @definition['resources'] Calamum::Config[:sort]? resources.sort : resources end |
#get_seperate_resources ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/calamum/doc_parser.rb', line 38 def get_seperate_resources extension = File.extname(Calamum::Config[:source]) path = File.("#{@definition['resources']}", File.dirname(Calamum::Config[:source])) case extension when '.json' then Dir["#{path}/*#{extension}"].map { |f| Yajl.load File.read(f) }.flatten.reduce({}, :merge) when '.yml' then Dir["#{path}/*#{extension}"].map { |f| YAML.load File.read(f) }.flatten.reduce({}, :merge) else raise 'unknown source file extension' end end |
#get_url ⇒ Object
9 10 11 |
# File 'lib/calamum/doc_parser.rb', line 9 def get_url @definition['url'] end |
#get_version ⇒ Object
17 18 19 |
# File 'lib/calamum/doc_parser.rb', line 17 def get_version @definition['version'] end |
#load_resources ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/calamum/doc_parser.rb', line 48 def load_resources get_resources.each do |name, methods| list = [] methods.each do |resource| if validate_resource?(resource) list << Calamum::Resource.new(resource) puts_info "#{resource['action']}: #{resource['uri']}" else puts_warning "Resource #{resource['action']}: #{resource['uri']} has incorrect definition" end end @resources[name] = list if list.any? end @resources end |
#validate_resource?(resource) ⇒ Boolean
64 65 66 |
# File 'lib/calamum/doc_parser.rb', line 64 def validate_resource?(resource) resource['uri'] && resource['action'] && resource['description'] && %{GET POST PUT DELETE}.include?(resource['action'].upcase) end |