Skip to content

Commit

Permalink
Added configure
Browse files Browse the repository at this point in the history
  • Loading branch information
ogom committed Jan 3, 2015
1 parent e2c5759 commit 3926358
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 ogom
Copyright (c) 2015 ogom

MIT License

Expand Down
7 changes: 4 additions & 3 deletions app/controllers/draw_erd/diagram_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ class DiagramController < ::DrawErd::ApplicationController
def index
@schemas = DrawErd::Diagram.schemas

title = 'erd'
path = 'draw-erd'
title = DrawErd.config.title
path = DrawErd.config.path

@image_file = File.join(path, "#{title}.png")

@domains = []
@domains = params['schemas'].keys if params.key?('schemas')

diagram = DrawErd::Diagram.new(File.join('public', 'images', path))
diagram.create(title, @domains)
diagram.create(title, @domains, DrawErd.config.attributes)
end
end
end
4 changes: 2 additions & 2 deletions app/models/draw_erd/diagram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def initialize(path)
FileUtils.mkdir_p(@path)
end

def create(title, domains=[], attributes=[:foreign_keys, :content])
def create(title, domains=[], attributes=false)
only = domains.map {|domain| domain.to_sym}
options = {
filetype: :png,
attributes: attributes,
title: title.to_s,
title: false,
only: only,
filename: File.join(@path, title.to_s)
}
Expand Down
2 changes: 1 addition & 1 deletion draw_erd.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency 'rails'
spec.add_dependency 'rails-erd'
spec.add_dependency 'rails-erd', '~> 1.1.0'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
Expand Down
16 changes: 16 additions & 0 deletions lib/draw_erd.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
require 'draw_erd/version'
require 'draw_erd/configure'
require 'draw_erd/default'
require 'draw_erd/engine'

module DrawErd
class << self
def configure
yield DrawErd::Configure
end

def config
DrawErd::Configure
end
end
end

DrawErd::Configure.setup
17 changes: 17 additions & 0 deletions lib/draw_erd/configure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module DrawErd
module Configure
class << self
attr_accessor :path, :title, :attributes

def setup
keys.each do |key|
instance_variable_set(:"@#{key}", DrawErd::Default.send(key))
end
end

def keys
@keys ||= %i[path title attributes]
end
end
end
end
25 changes: 25 additions & 0 deletions lib/draw_erd/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module DrawErd
module Default
PATH = 'draw-erd'.freeze
TITLE = 'erd'.freeze
ATTRIBUTES = [:foreign_keys, :content].freeze

class << self
def options
Hash[DrawErd::Configure.keys.map{|key| [key, send(key)]}]
end

def path
PATH
end

def title
TITLE
end

def attributes
ATTRIBUTES
end
end
end
end
2 changes: 1 addition & 1 deletion lib/draw_erd/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DrawErd
VERSION = '0.1.2'.freeze
VERSION = '0.2.0'.freeze
end
4 changes: 2 additions & 2 deletions spec/lib/version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'

describe DrawErd do
describe "VERSION" do
it "DrawErd::VERSION" do
describe ".version" do
it "returns #{DrawErd::VERSION}" do
expect(DrawErd::VERSION).to eq(DrawErd::VERSION)
end
end
Expand Down

0 comments on commit 3926358

Please sign in to comment.