Skip to content

Commit

Permalink
Merge pull request #6 from fotinakis/backwards-compatibility
Browse files Browse the repository at this point in the history
Make backwards compatible with ruby 1.9.3.
  • Loading branch information
fotinakis committed Jan 23, 2015
2 parents edc4e16 + 1dee9af commit 9cb03cf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: ruby
rvm:
- 1.9.3
- 2.1.1
- ruby-head
script: bundle exec rspec
12 changes: 5 additions & 7 deletions lib/swagger/blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ def self.included(base)
base.extend(ClassMethods)
end

module_function def build_root_json(swaggered_classes)
def self.build_root_json(swaggered_classes)
data = Swagger::Blocks::InternalHelpers.parse_swaggered_classes(swaggered_classes)
data[:root_node].as_json
end

module_function def build_api_json(resource_name, swaggered_classes)
def self.build_api_json(resource_name, swaggered_classes)
data = Swagger::Blocks::InternalHelpers.parse_swaggered_classes(swaggered_classes)
api_node = data[:api_node_map][resource_name.to_sym]
raise Swagger::Blocks::NotFoundError.new(
"Not found: swagger_api_root named #{resource_name}") if !api_node

# Aggregate all model definitions into a new ModelsNode tree and add it to the JSON.
temp_models_node = Swagger::Blocks::ModelsNode.call(name: 'models') { }
data[:models_nodes].each do |models_node|
temp_models_node.merge!(models_node)
end
data[:models_nodes].each { |models_node| temp_models_node.merge!(models_node) }
result = api_node.as_json
result.merge!(temp_models_node.as_json) if temp_models_node
result
Expand Down Expand Up @@ -130,10 +128,10 @@ def _swagger_nodes
class Node
attr_accessor :name

def self.call(name: nil, &block)
def self.call(options = {}, &block)
# Create a new instance and evaluate the block into it.
instance = new
instance.name = name if name # Set the first parameter given as the name.
instance.name = options[:name] if options[:name]
instance.instance_eval(&block)
instance
end
Expand Down
2 changes: 1 addition & 1 deletion swagger-blocks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.1'
spec.required_ruby_version = '>= 1.9.3'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
Expand Down

0 comments on commit 9cb03cf

Please sign in to comment.