framework 0.0.1 → 0.0.2

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: ba75921072b35b2f243539a2c8875c6eaabccd39
4
- data.tar.gz: 3091bbda391dcabdc6e04588d40b25cc12ef07e9
3
+ metadata.gz: 17ea2a57355b495eff2e3798ed32103017673a3a
4
+ data.tar.gz: 01739b92621f21c8122b34a5759e5f811615842f
5
5
  SHA512:
6
- metadata.gz: e1c690e3bfed331f6dd5206df9a3d6e1f5ff1f7ce7ab3394d1af9fe2cc0d71e82d9e9c3cc90adf39786467e8e2452e1520abd44947928b47aa00eb30bdb19458
7
- data.tar.gz: f09cafc01abb92a531662ae3b6dbb245f9c72f1e721cb9d76e4f820119ff4daf9354e63d005d68423c0f3a148f028941b8a79398c0bb04370c49b5b991a2f033
6
+ metadata.gz: 9fe435f8328873b76556566d8fadd6ea49911dc07763f95fcc63124c0b8b8ad39a2bda4e9af9e745079226c83a3163653f30bc34ddb184d1240b2181f0f0e1f6
7
+ data.tar.gz: 0a7d80ceeb19c004f9823fae991f36ac0d3c2d9a212d24fcb62b4fca3a229b2dbcc70ad3dc7ad956e162b4f99737bf9bf4ee33e9adf049ea9bcaa77e88dd19f9
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ Ruby Framework
2
+ =========
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/framework.svg)](http://badge.fury.io/rb/framework)
5
+
6
+ Framework to build Ruby applications for all your needs. Inspired by Rails, but clear and clean from any web-related backend.
7
+
8
+ ### Features
9
+
10
+ - Easy configuration to work with multiple databases
11
+ - ActiveRecord interface
12
+ - Customizable structure
13
+ - YAML configuration
14
+ - Appication generators
15
+ - Useful console mode
16
+ - ... Find more
17
+
18
+ ### When to use
19
+
20
+ - Obviously, you need a framework :)
21
+ - You need to quickly start a project from scratch
22
+ - You want to have your backend code to stay separate from any large frameworks (like Rails)
23
+ - You want to build some "worker" application running your business logic with no interface
24
+ - Setting up an interview? Use Framework!
25
+ - Wanna build web application? You can easily integrate your code into any web framework (Rack, Rails etc) (see below)
26
+ - You don't want to learn a new framework, you are the one who knows only Rails :)
27
+ - You want to test something quickly and you don't want to waste your time setting new environment up
28
+
29
+ ### Quick start
30
+
31
+ 1) Install Framework at the command prompt if you haven't yet:
32
+
33
+ ```shell
34
+ gem install framework
35
+ ```
36
+
37
+ 2) Create a new application:
38
+
39
+ ```shell
40
+ framework new myapp
41
+ ```
42
+
43
+ ### Run console to play
44
+
45
+ ```shell
46
+ rake console
47
+ ```
48
+
49
+ ![screen shot 2014-11-28 at 17 14 48](https://cloud.githubusercontent.com/assets/370635/5226522/dcfbdc42-7719-11e4-9af9-602d1e68e0fa.png)
50
+
51
+ ### Structure
52
+
53
+ Pretty similar to Rails (just a sample):
54
+
55
+ ```
56
+ .
57
+ |____app
58
+ | |____models
59
+ | | |____concerns
60
+ | | | |____.keep
61
+ | | |____task.rb
62
+ | | |____user.rb
63
+ | |____tasks
64
+ | | |____hello.rake
65
+ |____config
66
+ | |____application.yml
67
+ | |____databases.yml
68
+ | |____environment.rb
69
+ | |____initializers
70
+ | | |____time_zone.rb
71
+ |____db
72
+ | |____migrations
73
+ | | |____.keep
74
+ | | |____20141128085924_create_tasks.rb
75
+ | | |____20141128090211_create_users.rb
76
+ |____Gemfile
77
+ |____Gemfile.lock
78
+ |____lib
79
+ | |____.keep
80
+ |____Rakefile
81
+ |____README.md
82
+ ```
83
+
84
+ ### Configuration
85
+
86
+ Configurations are stored in `config/application.yml`. Note, that as opposed to Rails, even initializers and models are listed as custom paths in `autoload_paths` section. This gives you a flexibility to explicitly say which paths and what exactly used in your app. Don't need no initializers? Don't list them in autoload paths. Order matters.
87
+
88
+ ```yaml
89
+ development: &common
90
+ enable_logging: yes
91
+ autoload_paths:
92
+ - config/initializers
93
+ - app/models
94
+ default_timezone: 'Pacific Time (US & Canada)'
95
+
96
+ test:
97
+ <<: *common
98
+ enable_logging: no
99
+
100
+ staging:
101
+ <<: *common
102
+
103
+ production:
104
+ <<: *common
105
+ enable_logging: no
106
+ ```
107
+
108
+ ### More docu and updates coming soon
109
+
110
+ I encourage you to contribute! :)
@@ -36,15 +36,38 @@ module Framework
36
36
 
37
37
  def create_database!(name = nil)
38
38
  name ||= 'default'
39
- establish_postgres_connection(name)
40
- ActiveRecord::Base.connection.create_database(database_config[name][env]['database'])
41
- puts "The database #{database_config[name][env]['database']} has been successfully created"
39
+ cfg = database_config[name][env]
40
+
41
+ case cfg['adapter']
42
+ when 'postgresql'
43
+ establish_postgres_connection(name)
44
+ ActiveRecord::Base.connection.create_database(cfg['database'])
45
+ when 'sqlite3'
46
+ raise 'Database already exists' if File.exist?(cfg['database'])
47
+ establish_database_connection
48
+ else
49
+ raise "Unknown adapter '#{cfg['adapter']}'"
50
+ end
51
+
52
+ puts "The database #{cfg['database']} has been successfully created"
42
53
  end
43
54
 
44
55
  def drop_database!(name = nil)
45
56
  name ||= 'default'
46
- establish_postgres_connection(name)
47
- ActiveRecord::Base.connection.drop_database(database_config[name][env]['database'])
57
+ cfg = database_config[name][env]
58
+
59
+ case cfg['adapter']
60
+ when 'postgresql'
61
+ establish_postgres_connection(name)
62
+ ActiveRecord::Base.connection.drop_database(cfg['database'])
63
+ when 'sqlite3'
64
+ require 'pathname'
65
+ path = Pathname.new(cfg['database']).to_s
66
+ FileUtils.rm(path) if File.exist?(path)
67
+ else
68
+ raise "Unknown adapter '#{cfg['adapter']}'"
69
+ end
70
+
48
71
  puts "The database #{database_config[name][env]['database']} has been successfully dropped"
49
72
  end
50
73
 
data/lib/framework/cli.rb CHANGED
@@ -1,181 +1,12 @@
1
- require 'active_support/core_ext/string/inflections'
2
- require 'active_support/core_ext/string/strip'
3
1
  require 'thor'
4
2
 
5
- require 'framework/version'
3
+ require 'framework'
4
+ require 'framework/generators/multi_generator'
5
+ require 'framework/generators/application_generator'
6
6
 
7
7
  module Framework
8
- class AppGenerator < Thor::Group
9
- include Thor::Actions
10
-
11
- argument :name
12
-
13
- def self.source_root
14
- File.dirname(__FILE__)
15
- end
16
-
17
- def create_base_directories
18
- empty_directory 'app/migrations'
19
- create_file 'app/migrations/.keep'
20
-
21
- empty_directory 'app/models'
22
- empty_directory 'app/models/concerns'
23
- create_file 'app/models/concerns/.keep'
24
-
25
- empty_directory 'lib'
26
- create_file 'lib/.keep'
27
-
28
- empty_directory 'db'
29
- empty_directory 'db/migrations'
30
- create_file 'db/migrations/.keep'
31
-
32
- end
33
-
34
- def create_application_config
35
- create_file 'config/application.yml' do
36
- <<-CONFIG.strip_heredoc
37
- development: &common
38
- enable_logging: yes
39
- autoload_paths:
40
- - config/initializers
41
- - app/models
42
- default_timezone: 'Pacific Time (US & Canada)'
43
-
44
- test:
45
- <<: *common
46
- enable_logging: no
47
-
48
- staging:
49
- <<: *common
50
-
51
- production:
52
- <<: *common
53
- enable_logging: no
54
- CONFIG
55
- end
56
- end
57
-
58
- def create_database_config
59
- db_name = name.underscore
60
-
61
- create_file 'config/databases.yml' do
62
- <<-CONFIG.strip_heredoc
63
- # Defult database is used by default.
64
- # Any models locating at app/models root directory will point to this database by default.
65
- default:
66
- development: &common
67
- adapter: postgresql
68
- username:
69
- password:
70
- database: #{db_name}_development
71
- min_messages: WARNING
72
- reconnect: true
73
- pool: 5
74
- encoding: unicode
75
- host: localhost
76
-
77
- test:
78
- <<: *common
79
- database: #{db_name}_test
80
-
81
- production:
82
- <<: *common
83
- database: #{db_name}_production
84
-
85
- # Custom one. Models located at app/models/second_one path will point to this database by default.
86
- second_one:
87
- development: &common
88
- adapter: postgresql
89
- username:
90
- password:
91
- database: second_sample_development
92
- min_messages: WARNING
93
- reconnect: true
94
- pool: 5
95
- encoding: unicode
96
- host: localhost
97
-
98
- test:
99
- <<: *common
100
- database: second_sample_test
101
-
102
- production:
103
- <<: *common
104
- database: second_sample_production
105
- CONFIG
106
- end
107
- end
108
-
109
- def create_environment
110
- create_file 'config/environment.rb' do
111
- <<-CONFIG.strip_heredoc
112
- # Set up gems listed in the Gemfile.
113
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
114
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
115
-
116
- require 'framework'
117
-
118
- Bundler.require(:default, Framework.env)
119
-
120
- Framework::Application.new do |app|
121
- app.init!
122
- end
123
- CONFIG
124
- end
125
- end
126
-
127
- def create_gemfile
128
- create_file 'Gemfile' do
129
- <<-CONFIG.strip_heredoc
130
- source 'https://rubygems.org'
131
-
132
- gem 'framework', '#{Framework::VERSION}'
133
- gem 'pg'
134
- CONFIG
135
- end
136
- end
137
-
138
- def create_rakefile
139
- create_file 'Rakefile' do
140
- <<-CONFIG.strip_heredoc
141
- # Add your own tasks in files placed in lib/tasks ending in .rake,
142
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
143
-
144
- require 'framework'
145
- require 'framework/rake'
146
-
147
- Dir["\#{Dir.pwd}/app/tasks/**/*.rake"].each(&method(:load))
148
- CONFIG
149
- end
150
- end
151
-
152
- def create_sample_tasks
153
- empty_directory 'app/tasks'
154
- create_file 'app/tasks/hello.rake' do
155
- <<-RAKE.strip_heredoc
156
- task hello: :environment do
157
- Framework::Logger.disappointment("Hello from: Framework v#{Framework::VERSION}")
158
- end
159
- RAKE
160
- end
161
- end
162
-
163
- def create_sample_initializers
164
- empty_directory 'config/initializers'
165
- create_file 'config/initializers/time_zone.rb' do
166
- <<-CONFIG.strip_heredoc
167
- # Sample usage of application config
168
- Time.zone = Framework.app.config['default_timezone']
169
- CONFIG
170
- end
171
- end
172
-
173
- def create_readme
174
- create_file 'README.md', "This app utilizes Framework v#{Framework::VERSION} and rocks MIT license."
175
- end
176
- end
177
-
178
8
  class Cli < Thor
179
- register(Framework::AppGenerator, 'new', 'new APP_NAME', 'Generates new application')
9
+ register(Framework::ApplicationGenerator, 'new', 'new APP_NAME', 'Generates new application')
10
+ register(Framework::MultiGenerator, 'generate', 'generate <migration>', 'Generates the thing you want')
180
11
  end
181
12
  end
@@ -0,0 +1,170 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'active_support/core_ext/string/strip'
3
+
4
+ module Framework
5
+ class ApplicationGenerator < Thor::Group
6
+ include Thor::Actions
7
+
8
+ argument :name
9
+
10
+ def self.source_root
11
+ File.dirname(__FILE__)
12
+ end
13
+
14
+ def create_base_directories
15
+ empty_directory 'app/models'
16
+ empty_directory 'app/models/concerns'
17
+ create_file 'app/models/concerns/.keep'
18
+
19
+ empty_directory 'lib'
20
+ create_file 'lib/.keep'
21
+
22
+ empty_directory 'db'
23
+ empty_directory 'db/migrations'
24
+ create_file 'db/migrations/.keep'
25
+ end
26
+
27
+ def create_application_config
28
+ create_file 'config/application.yml' do
29
+ <<-CONFIG.strip_heredoc
30
+ development: &common
31
+ enable_logging: yes
32
+ autoload_paths:
33
+ - config/initializers
34
+ - app/models
35
+ default_timezone: 'Pacific Time (US & Canada)'
36
+
37
+ test:
38
+ <<: *common
39
+ enable_logging: no
40
+
41
+ staging:
42
+ <<: *common
43
+
44
+ production:
45
+ <<: *common
46
+ enable_logging: no
47
+ CONFIG
48
+ end
49
+ end
50
+
51
+ def create_database_config
52
+ db_name = name.underscore
53
+
54
+ create_file 'config/databases.yml' do
55
+ <<-CONFIG.strip_heredoc
56
+ # Defult database is used by default.
57
+ # Any models locating at app/models root directory will point to this database by default.
58
+ default:
59
+ development: &common
60
+ adapter: postgresql
61
+ username:
62
+ password:
63
+ database: #{db_name}_development
64
+ min_messages: WARNING
65
+ reconnect: true
66
+ pool: 5
67
+ encoding: unicode
68
+ host: localhost
69
+
70
+ test:
71
+ <<: *common
72
+ database: #{db_name}_test
73
+
74
+ production:
75
+ <<: *common
76
+ database: #{db_name}_production
77
+
78
+ # Custom one. Models located at app/models/second_one path will point to this database by default.
79
+ second_one:
80
+ development: &common
81
+ adapter: postgresql
82
+ username:
83
+ password:
84
+ database: second_sample_development
85
+ min_messages: WARNING
86
+ reconnect: true
87
+ pool: 5
88
+ encoding: unicode
89
+ host: localhost
90
+
91
+ test:
92
+ <<: *common
93
+ database: second_sample_test
94
+
95
+ production:
96
+ <<: *common
97
+ database: second_sample_production
98
+ CONFIG
99
+ end
100
+ end
101
+
102
+ def create_environment
103
+ create_file 'config/environment.rb' do
104
+ <<-CONFIG.strip_heredoc
105
+ # Set up gems listed in the Gemfile.
106
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
107
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
108
+
109
+ require 'framework'
110
+
111
+ Bundler.require(:default, Framework.env)
112
+
113
+ Framework::Application.new do |app|
114
+ app.init!
115
+ end
116
+ CONFIG
117
+ end
118
+ end
119
+
120
+ def create_gemfile
121
+ create_file 'Gemfile' do
122
+ <<-CONFIG.strip_heredoc
123
+ source 'https://rubygems.org'
124
+
125
+ gem 'framework', '#{Framework::VERSION}'
126
+ gem 'pg'
127
+ CONFIG
128
+ end
129
+ end
130
+
131
+ def create_rakefile
132
+ create_file 'Rakefile' do
133
+ <<-CONFIG.strip_heredoc
134
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
135
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
136
+
137
+ require 'framework'
138
+ require 'framework/rake'
139
+
140
+ Dir["\#{Dir.pwd}/app/tasks/**/*.rake"].each(&method(:load))
141
+ CONFIG
142
+ end
143
+ end
144
+
145
+ def create_sample_tasks
146
+ empty_directory 'app/tasks'
147
+ create_file 'app/tasks/hello.rake' do
148
+ <<-RAKE.strip_heredoc
149
+ task hello: :environment do
150
+ Framework::Logger.disappointment("Hello from: Framework v#{Framework::VERSION}")
151
+ end
152
+ RAKE
153
+ end
154
+ end
155
+
156
+ def create_sample_initializers
157
+ empty_directory 'config/initializers'
158
+ create_file 'config/initializers/time_zone.rb' do
159
+ <<-CONFIG.strip_heredoc
160
+ # Sample usage of application config
161
+ Time.zone = Framework.app.config['default_timezone']
162
+ CONFIG
163
+ end
164
+ end
165
+
166
+ def create_readme
167
+ create_file 'README.md', "This app utilizes Framework v#{Framework::VERSION} and rocks MIT license."
168
+ end
169
+ end
170
+ end
@@ -1,8 +1,11 @@
1
+ require 'framework/migration'
1
2
  require 'erb'
2
3
 
3
4
  module Framework
4
5
  class MigrationGenerator
5
6
 
7
+ # @param [String] db_name
8
+ # @param [String] migration_name
6
9
  def initialize(db_name: db_name, migration_name: name)
7
10
  @db_name = db_name.underscore
8
11
  @migration_name = migration_name.underscore
@@ -16,7 +19,7 @@ module Framework
16
19
  migration_file << ERB.new(template).result(context)
17
20
  migration_file.close
18
21
 
19
- Framework.app.hint "Generated migration: #@path"
22
+ p "Generated migration: #@path"
20
23
  end
21
24
 
22
25
  def templates_path
@@ -43,7 +46,7 @@ module Framework
43
46
  def load_migrations
44
47
  Dir["./db/migrations/**/*.rb"].each(&method(:load))
45
48
  rescue
46
- raise "An error was occurred"
49
+ raise 'An error was occurred'
47
50
  end
48
51
 
49
52
  def validate!
@@ -0,0 +1,22 @@
1
+ require 'framework/generators/migration_generator'
2
+
3
+ module Framework
4
+ class MultiGenerator < Thor::Group
5
+ argument :target_type
6
+ argument :target_name
7
+
8
+ def self.source_root
9
+ File.dirname(__FILE__)
10
+ end
11
+
12
+ def generate
13
+ case target_type
14
+ when 'migration'
15
+ Framework::MigrationGenerator.new(db_name: (ENV['DB_NAME'] || 'default'), migration_name: target_name).generate
16
+ else
17
+ raise "Don't know how to build task 'generate #{target_type}'"
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -2,7 +2,7 @@ desc "Runs irb console and initializes the application"
2
2
  task :console, :env do |_, args|
3
3
  require 'irb'
4
4
 
5
- unless env = ENV['ANALYTICS_ENV']
5
+ unless env = ENV['FRAMEWORK_ENV']
6
6
  env = args[:env] || Framework::DEFAULT_ENV
7
7
  end
8
8
 
@@ -1,3 +1,3 @@
1
1
  task :environment do
2
- Framework::Application.new(ENV['ANALYTICS_ENV'] || 'development').init!
2
+ Framework::Application.new.init!
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Framework
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
data/lib/framework.rb CHANGED
@@ -25,10 +25,3 @@ module Framework
25
25
  end
26
26
  end
27
27
 
28
- begin
29
- Bundler.require(:default, Framework.env)
30
- rescue Bundler::BundlerError => e
31
- $stderr.puts e.message
32
- $stderr.puts "Run `bundle install` to install missing gems"
33
- exit e.status_code
34
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Nikolaevich Zinin
@@ -158,6 +158,7 @@ extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - LICENSE
161
+ - README.md
161
162
  - Rakefile
162
163
  - bin/framework
163
164
  - lib/framework.rb
@@ -165,7 +166,9 @@ files:
165
166
  - lib/framework/cli.rb
166
167
  - lib/framework/db_listener.rb
167
168
  - lib/framework/extensions/active_record/base_extension.rb
169
+ - lib/framework/generators/application_generator.rb
168
170
  - lib/framework/generators/migration_generator.rb
171
+ - lib/framework/generators/multi_generator.rb
169
172
  - lib/framework/logger.rb
170
173
  - lib/framework/migration.rb
171
174
  - lib/framework/rake.rb