dandy 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35729ef648356d307df4cbb9a49aa1df7e053949
4
- data.tar.gz: 695e1200d2c7066ed4f989842322437c5635779b
3
+ metadata.gz: 874927c6a6c9fe878b77341cb699df8e1826a4c4
4
+ data.tar.gz: c29ffb2cf1211bb9a5eedb21c93c2117171e15af
5
5
  SHA512:
6
- metadata.gz: 52323c799596e094a5f2dd26a3a0b178f5016696fa4cd7cf33b0df4add8209f5fda43e908cdd1cfa26024bca443f599e048ecd7f17d85def852a3797e111b71b
7
- data.tar.gz: 37757ebdc264e506788c398c0c525dac7f2b2cd882b27501283434faa8b0c60beeb813b85eb885eecacdac0f904e54f0bc34d35c527f725d1854c9275b4bada5
6
+ metadata.gz: 1feb5fbc692297aba11bde80a584aeb7679d2cfab5d1144dba410e6f8178d38fd30ce0b088a897f7a08048cd35a1763c707d32ea91277d6a2ec102a34e854d6f
7
+ data.tar.gz: 5eb3ba4c287233663f58be493a4f9ed5fcaadc5f1ebdeddc1a80de2f46e4f3f4c60a7f838e5b47fa0af07607bd302fb503024ac94628ea8179ed6b7ae0558300
@@ -10,16 +10,30 @@ module Dandy
10
10
  end
11
11
 
12
12
  desc 'new NAME', 'Create new Dandy application'
13
+ method_options :jet_set => :boolean
13
14
  def new(name)
14
- copy_file 'templates/app/app.rb', "#{name}/app/app.rb"
15
+
16
+ if options[:jet_set]
17
+ copy_file 'templates/app/app_jet_set.rb', "#{name}/app/app.rb"
18
+ copy_file 'templates/Gemfile_jet_set', "#{name}/Gemfile"
19
+ copy_file 'templates/db/mapping.rb', "#{name}/db/mapping.rb"
20
+ copy_file 'templates/actions/common/open_db_session.rb', "#{name}/app/actions/common/open_db_session.rb"
21
+ else
22
+ copy_file 'templates/app/app.rb', "#{name}/app/app.rb"
23
+ copy_file 'templates/Gemfile', "#{name}/Gemfile"
24
+ end
25
+
15
26
  copy_file 'templates/app/app.routes', "#{name}/app/app.routes"
16
27
  copy_file 'templates/dandy.yml', "#{name}/dandy.yml"
17
28
  copy_file 'templates/config.ru', "#{name}/config.ru"
18
29
  copy_file 'templates/views/show_welcome.json.jbuilder', "#{name}/app/views/show_welcome.json.jbuilder"
19
30
  copy_file 'templates/actions/common/handle_errors.rb', "#{name}/app/actions/common/handle_errors.rb"
20
- copy_file 'templates/Gemfile', "#{name}/Gemfile"
21
31
  template 'templates/actions/welcome.tt', "#{name}/app/actions/welcome.rb", {app_name: name}
22
32
 
33
+ if options[:jet_set]
34
+ insert_into_file "#{name}/app/app.routes", " :before -> common/open_db_session\n", :after => ".->\n"
35
+ end
36
+
23
37
  inside name do
24
38
  run 'bundle'
25
39
  end
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rack-cors'
4
+ gem 'hypo'
4
5
  gem 'dandy'
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rack-cors'
4
+ gem 'hypo'
5
+ gem 'dandy'
6
+
7
+ gem 'sqlite'
8
+ #gem 'pg'
9
+
10
+ gem 'sequel'
11
+ gem 'jet_set'
@@ -0,0 +1,24 @@
1
+ require 'sequel'
2
+ require 'jet_set'
3
+ require 'logger'
4
+
5
+ class OpenDbSession
6
+ def initialize(container, dandy_config, dandy_env)
7
+ @container = container
8
+ @config = dandy_config
9
+ @dandy_env = dandy_env
10
+ end
11
+
12
+ def call
13
+ # Instead of :url you can specify required Sequel connection parameters in dandy.yml.
14
+ # Additional details about Sequel connection configuration
15
+ # see at http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html
16
+ connection = Sequel.connect(@config[:db][:url])
17
+
18
+ if @dandy_env == 'development'
19
+ connection.loggers << Logger.new($stdout)
20
+ end
21
+
22
+ JetSet::open_session(connection, :dandy_request)
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'dandy'
2
+ require 'jet_set'
3
+ require './db/mapping'
4
+
5
+ class App < Dandy::App
6
+ include Mapping
7
+
8
+ def initialize(container = Hypo::Container.new)
9
+ super(container)
10
+
11
+ JetSet::init(load_mapping, container)
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ path:
2
+ dependencies:
3
+ - app/actions
4
+ views: app/views
5
+ routes: app/app.routes
6
+ action:
7
+ async_timeout: 10 # in seconds
8
+ db:
9
+ url: sqlite:/ # replace it with connection string to your source
@@ -0,0 +1,25 @@
1
+ # Don't forget add dependencies
2
+ # require './domain/user'
3
+ # require './domain/invoice'
4
+
5
+ module Mapping
6
+ def load_mapping
7
+ JetSet::map do
8
+ # Example:
9
+ #
10
+ # entity User do
11
+ # field :first_name
12
+ # field :last_name
13
+ # field :company
14
+ # collection :invoices, type: Invoice
15
+ # end
16
+ #
17
+ # entity Invoice do
18
+ # field :amount
19
+ # field :date
20
+ # field :created_at
21
+ # reference :user, type: User
22
+ # end
23
+ end
24
+ end
25
+ end
@@ -14,7 +14,7 @@ module Dandy
14
14
  end
15
15
 
16
16
  @types.each do |type|
17
- @container.register(type).using_lifetime(:scope).bound_to(:dandy_request)
17
+ @container.register(type[:class], type[:path].to_sym).using_lifetime(:scope).bound_to(:dandy_request)
18
18
  end
19
19
  end
20
20
  end
@@ -8,14 +8,17 @@ module Dandy
8
8
  types = []
9
9
  @directories.each do |directory|
10
10
  dir = File.join(directory, '**/*')
11
- files = Dir.glob(dir).reject {|file_path| File.directory? file_path}
11
+ files = Dir.glob(dir).reject {|file_path| File.directory?(file_path)}
12
12
 
13
13
  files.each do |file|
14
- path = File.join Dir.pwd, file
14
+ path = File.join(Dir.pwd, file)
15
15
  require path
16
16
  file_name = File.basename(file).gsub(File.extname(file), '')
17
17
  class_name = file_name.split('_').each(&:capitalize!).join('')
18
- types << Object.const_get(class_name)
18
+ types << {
19
+ class: Object.const_get(class_name),
20
+ path: file.gsub(File.extname(file), '').gsub(directory + '/', '')
21
+ }
19
22
  end
20
23
  end
21
24
 
@@ -7,10 +7,15 @@ module Dandy
7
7
 
8
8
  def read
9
9
  path = File.join('./', @config[:path][:routes])
10
- content = File.read(path)
10
+ raw_content = File.read(path)
11
+
12
+ raw_content.gsub!(/\\\s*\n+\s*->/, '->')
13
+ raw_content.gsub!(/\\\s*\n+\s*=>/, '=>')
14
+ raw_content.gsub!(/\\\s*\n+\s*=\*/, '=>')
15
+
11
16
 
12
17
  # use '^' instead spaces and tabs
13
- raw_content = content.gsub(/\t/, ' ')
18
+ raw_content = raw_content.gsub(/\t/, ' ')
14
19
  .gsub(' ', '^')
15
20
  .gsub(' ', '')
16
21
 
@@ -20,7 +25,7 @@ module Dandy
20
25
  ###
21
26
  raw_content = raw_content.gsub('->', '*>').gsub('<-', '<*')
22
27
 
23
- raw_content.gsub!("\n", ';') + ';'
28
+ raw_content.gsub("\n", ';') + ';'
24
29
  end
25
30
  end
26
31
  end
@@ -40,7 +40,7 @@ grammar Syntax
40
40
  end
41
41
 
42
42
  rule command
43
- (arrow result_name [a-z0-9_]+) 1..1 <Command>
43
+ (arrow result_name [a-z0-9_\/]+) 1..1 <Command>
44
44
  end
45
45
 
46
46
  rule result_name
data/lib/dandy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dandy
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dandy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kalinkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-01 00:00:00.000000000 Z
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hypo
@@ -210,12 +210,16 @@ files:
210
210
  - lib/dandy/extensions/hash.rb
211
211
  - lib/dandy/generators/cli.rb
212
212
  - lib/dandy/generators/templates/Gemfile
213
+ - lib/dandy/generators/templates/Gemfile_jet_set
213
214
  - lib/dandy/generators/templates/actions/common/handle_errors.rb
215
+ - lib/dandy/generators/templates/actions/common/open_db_session.rb
214
216
  - lib/dandy/generators/templates/actions/welcome.tt
215
217
  - lib/dandy/generators/templates/app/app.rb
216
218
  - lib/dandy/generators/templates/app/app.routes
219
+ - lib/dandy/generators/templates/app/app_jet_set.rb
217
220
  - lib/dandy/generators/templates/config.ru
218
- - lib/dandy/generators/templates/silicon.yml
221
+ - lib/dandy/generators/templates/dandy.yml
222
+ - lib/dandy/generators/templates/db/mapping.rb
219
223
  - lib/dandy/generators/templates/views/show_welcome.json.jbuilder
220
224
  - lib/dandy/loaders/dependency_loader.rb
221
225
  - lib/dandy/loaders/template_loader.rb
@@ -1,7 +0,0 @@
1
- path:
2
- dependencies:
3
- - app/actions
4
- views: app/views
5
- routes: app/app.routes
6
- action:
7
- async_timeout: 10 # in seconds