fox 0.0.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +196 -14
- data/bin/fox +28 -8
- data/fox.gemspec +41 -3
- data/lib/fox.rb +23 -10
- data/lib/fox/cli.rb +17 -0
- data/lib/fox/configuration.rb +48 -0
- data/lib/fox/core_ext.rb +8 -0
- data/lib/fox/core_ext/array.rb +51 -0
- data/lib/fox/core_ext/hash.rb +17 -0
- data/lib/fox/core_ext/io_binary_read.rb +20 -0
- data/lib/fox/error.rb +8 -0
- data/lib/fox/error/errors.rb +232 -0
- data/lib/fox/interface/thor/all.rb +34 -0
- data/lib/fox/interface/thor/configuration.rb +71 -0
- data/lib/fox/interface/thor/create.rb +49 -0
- data/lib/fox/interface/thor/default.rb +67 -0
- data/lib/fox/interface/thor/init.rb +57 -0
- data/lib/fox/interface/thor/mixin/config_choice.rb +3 -3
- data/lib/fox/interface/thor/mixin/configuration.rb +1 -1
- data/lib/fox/interface/thor/mixin/database.rb +129 -0
- data/lib/fox/interface/thor/mixin/default.rb +6 -0
- data/lib/fox/interface/thor/mixin/default_model.rb +13 -0
- data/lib/fox/interface/thor/mixin/generators/base_generator.rb +35 -0
- data/lib/fox/interface/thor/mixin/generators/structure.rb +41 -0
- data/lib/fox/interface/thor/mixin/generators/template_loader.rb +48 -0
- data/lib/fox/interface/thor/mixin/history.rb +12 -0
- data/lib/fox/interface/thor/mixin/logger.rb +2 -2
- data/lib/fox/interface/thor/mixin/model.rb +19 -0
- data/lib/fox/interface/thor/new.thor +74 -0
- data/lib/fox/interface/thor/version.rb +59 -0
- data/lib/fox/library/choice.rb +160 -0
- data/lib/fox/library/logger.rb +175 -0
- data/lib/fox/library/project_builder.rb +83 -0
- data/lib/fox/library/secure_config.rb +114 -0
- metadata +298 -7
- data/lib/fox/interface/thor/version.thor +0 -33
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# System include
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
# Custom include
|
7
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/default' )
|
8
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/logger' )
|
9
|
+
|
10
|
+
# require File.expand_path(File.dirname(__FILE__) + '/mixin/generators/java_generator')
|
11
|
+
|
12
|
+
|
13
|
+
# @class class Create
|
14
|
+
# @brief Generate scaffolded output
|
15
|
+
class Create < Thor
|
16
|
+
|
17
|
+
# Include various partials
|
18
|
+
include ::Mixin::Default
|
19
|
+
include ::Mixin::Logger
|
20
|
+
|
21
|
+
default_task :create
|
22
|
+
|
23
|
+
GENS = Mixin::Generators
|
24
|
+
|
25
|
+
# # @fn def create file {{{
|
26
|
+
# # @brief FIXME
|
27
|
+
# #
|
28
|
+
# desc "create FOLDER", "generate from thrift `FILE` a template for `languages`, and write result into `output` directory (gen-* packages)"
|
29
|
+
# option :output, :aliases => :o, :type => :string, :default => Dir.pwd
|
30
|
+
# option :version, :aliases => :v, :type => :string, :default => "0.0.1"
|
31
|
+
# option :java
|
32
|
+
|
33
|
+
# def create file
|
34
|
+
# @logger.message :info, "Running Fox #create for #{file.to_s}"
|
35
|
+
#
|
36
|
+
# output = options["output"]
|
37
|
+
# version = options["version"]
|
38
|
+
#
|
39
|
+
# langs = options.keys & languages
|
40
|
+
#
|
41
|
+
# langs.each do |lang|
|
42
|
+
# klass = Object.const_get("#{GENS}::JavaGenerator")
|
43
|
+
# klass.generate( file, version, output )
|
44
|
+
# end
|
45
|
+
# end # def create # }}}
|
46
|
+
|
47
|
+
end # of class CreateCommand
|
48
|
+
|
49
|
+
# vim:ts=2:tw=100:wm=100:syntax=ruby
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# System include
|
4
|
+
require 'thor'
|
5
|
+
require 'data_mapper'
|
6
|
+
|
7
|
+
# Custom include
|
8
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/default' )
|
9
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/logger' )
|
10
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/database' )
|
11
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/version' )
|
12
|
+
|
13
|
+
# @class class Default
|
14
|
+
# @brief work with user Structures
|
15
|
+
class Default < Thor
|
16
|
+
|
17
|
+
# Include various partials
|
18
|
+
include ::Mixin::Default
|
19
|
+
include ::Mixin::Logger
|
20
|
+
include ::Mixin::Database
|
21
|
+
|
22
|
+
default_task :set
|
23
|
+
|
24
|
+
# @fn def set version {{{
|
25
|
+
# @brief set default Model for work
|
26
|
+
#
|
27
|
+
# @param [String] - version number
|
28
|
+
desc "set MODEL VERSION", "set default MODEL and VERSION for work"
|
29
|
+
def set model, version = nil
|
30
|
+
@logger.message :info, "Running Fox #default for #{model}"
|
31
|
+
|
32
|
+
models = all_models.map(&:name)
|
33
|
+
if models.map(&:downcase).include?(model.downcase)
|
34
|
+
set_default_model model
|
35
|
+
@logger.message :info, "Set '#{model.to_s.capitalize}' model as default Structure for work"
|
36
|
+
|
37
|
+
if version
|
38
|
+
Version.new.set(version)
|
39
|
+
end
|
40
|
+
|
41
|
+
else
|
42
|
+
abort(%Q(Model '#{model.capitalize}' not found.\n Available models:\n#{models.sort.join("\n")}))
|
43
|
+
end
|
44
|
+
end # of def set # }}}
|
45
|
+
|
46
|
+
# @fn def now {{{
|
47
|
+
desc "now", "return default Model"
|
48
|
+
def now
|
49
|
+
@logger.message :info, "Running Fox Default#now"
|
50
|
+
default_model = get_default_model
|
51
|
+
|
52
|
+
if default_model.nil?
|
53
|
+
puts "Default model not set"
|
54
|
+
puts "Set with `fox default set <ModelName>`"
|
55
|
+
else
|
56
|
+
version = if default_model.version.nil?
|
57
|
+
"\nversion not defined. Define with `fox version set <Version>`"
|
58
|
+
else
|
59
|
+
"version: #{default_model.version}"
|
60
|
+
end
|
61
|
+
puts "Default Model: #{default_model.name} #{version}"
|
62
|
+
end
|
63
|
+
end # of def now
|
64
|
+
|
65
|
+
end # of class Default
|
66
|
+
|
67
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# System includes
|
4
|
+
require 'thor'
|
5
|
+
require 'data_mapper'
|
6
|
+
require 'dm-migrations'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
# Custom includes
|
10
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/default' )
|
11
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/logger' )
|
12
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/history' )
|
13
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/model' )
|
14
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/default_model' )
|
15
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/mixin/database' )
|
16
|
+
|
17
|
+
|
18
|
+
# @class class Init < Thor
|
19
|
+
# @brief Initializes project default config environment
|
20
|
+
class Init < Thor
|
21
|
+
|
22
|
+
# Include various partials
|
23
|
+
include ::Mixin::Default
|
24
|
+
include ::Mixin::Logger
|
25
|
+
include ::Mixin::Database
|
26
|
+
|
27
|
+
default_task :init
|
28
|
+
|
29
|
+
# @fn def init # {{{
|
30
|
+
# @brief initialize project, create database for project
|
31
|
+
desc 'init', 'initialize project'
|
32
|
+
option :force, :aliases => :f
|
33
|
+
def init
|
34
|
+
|
35
|
+
path_to_db_folder = "#{Dir.pwd}/.fox"
|
36
|
+
db_path = "#{path_to_db_folder}/#{default_db_name}"
|
37
|
+
|
38
|
+
# if database exist need stop
|
39
|
+
abort("(EE) Found $PWD/.fox - Project already initialized, aborting") if( File.exist?(db_path) && !options['force'] )
|
40
|
+
|
41
|
+
FileUtils.mkdir_p("#{path_to_db_folder}")
|
42
|
+
|
43
|
+
DataMapper.setup(:default, %Q(sqlite:///#{db_path}))
|
44
|
+
DataMapper.auto_migrate!
|
45
|
+
DataMapper.finalize
|
46
|
+
|
47
|
+
puts "(II) Project initialized"
|
48
|
+
end # of def init }}}
|
49
|
+
|
50
|
+
private
|
51
|
+
def default_db_name
|
52
|
+
"fox.db"
|
53
|
+
end
|
54
|
+
|
55
|
+
end # if class Init
|
56
|
+
|
57
|
+
# vim:ts=2:tw=100:wm=100:syntax=ruby
|
@@ -9,8 +9,8 @@ module Mixin
|
|
9
9
|
module ConfigChoice
|
10
10
|
|
11
11
|
def config_choice
|
12
|
-
defaults = YAML.load_file(File.expand_path( File.dirname( __FILE__ ) + '/../../../template/default_values.yml'))
|
13
|
-
defaults['
|
12
|
+
defaults = YAML.load_file(File.expand_path( File.dirname( __FILE__ ) + '/../../../template/config/default_values.yml'))
|
13
|
+
defaults['fox'].each_key { |key| choice_option(defaults['fox'], key) }
|
14
14
|
defaults
|
15
15
|
end
|
16
16
|
|
@@ -24,4 +24,4 @@ module Mixin
|
|
24
24
|
end # of module Mixin
|
25
25
|
|
26
26
|
|
27
|
-
# vim:ts=2:tw=100:wm=100:syntax=ruby
|
27
|
+
# vim:ts=2:tw=100:wm=100:syntax=ruby
|
@@ -16,7 +16,7 @@ module Mixin
|
|
16
16
|
def initialize *args
|
17
17
|
super
|
18
18
|
unless File.exist?("~/.fox/config.yaml")
|
19
|
-
|
19
|
+
abort("Could not find configuration file in ~/.fox/config.yaml. Please run 'fox config:generate' to generate it.")
|
20
20
|
end
|
21
21
|
end # }}}
|
22
22
|
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# System includes
|
2
|
+
require 'data_mapper'
|
3
|
+
|
4
|
+
# Custom includes
|
5
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/history' )
|
6
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/model' )
|
7
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/default_model' )
|
8
|
+
|
9
|
+
# @module module Mixin
|
10
|
+
# @brief Mixin module contains various functions to be used in other components
|
11
|
+
module Mixin
|
12
|
+
|
13
|
+
# @module Database Module
|
14
|
+
# @brief Module wrapper around database tasks
|
15
|
+
module Database
|
16
|
+
extend self
|
17
|
+
|
18
|
+
DataMapper.setup(:default, %Q(sqlite:///#{Dir.pwd}/.fox/fox.db))
|
19
|
+
|
20
|
+
# @fn def write command # {{{
|
21
|
+
# @brief save command in database
|
22
|
+
#
|
23
|
+
# @param [String] command - command name
|
24
|
+
#
|
25
|
+
# @param [Array] arguments - arguments for command
|
26
|
+
def add_command command, *arguments
|
27
|
+
history = History.new
|
28
|
+
history.command = command
|
29
|
+
history.arguments = arguments.join(" ")
|
30
|
+
history.save
|
31
|
+
end # of def write }}}
|
32
|
+
|
33
|
+
# @fn def add_model model_name, version, uuid # {{{
|
34
|
+
# @brief save Model into database
|
35
|
+
#
|
36
|
+
# @param [String] model_name - name of Structure
|
37
|
+
#
|
38
|
+
# @param [String] version - version of Structure
|
39
|
+
#
|
40
|
+
# @param [String] uuid - uuid of Structure
|
41
|
+
def add_model model_name, version, uuid
|
42
|
+
model = Model.new
|
43
|
+
model.name = model_name
|
44
|
+
model.version = version
|
45
|
+
model.uuid = uuid
|
46
|
+
|
47
|
+
model.save
|
48
|
+
end # of def add_model }}}
|
49
|
+
|
50
|
+
# @fn def set_default_model model_name # {{{
|
51
|
+
# @brief Set default Model for usage
|
52
|
+
#
|
53
|
+
# @param [String] - model_name - name of Structure
|
54
|
+
def set_default_model model_name
|
55
|
+
# clear all models, when set default
|
56
|
+
DefaultModel.destroy!
|
57
|
+
default_model = DefaultModel.new
|
58
|
+
default_model.name = model_name
|
59
|
+
default_model.save
|
60
|
+
end # of set_default_model }}}
|
61
|
+
|
62
|
+
# @fn def get_default_model # {{{
|
63
|
+
# @brief return current default model
|
64
|
+
def get_default_model
|
65
|
+
DefaultModel.first
|
66
|
+
end # of def get_default_model }}}
|
67
|
+
|
68
|
+
# @fn def clear_default_model # {{{
|
69
|
+
# @brief remove default model
|
70
|
+
def clear_default_model
|
71
|
+
DefaultModel.destroy!
|
72
|
+
end # of def clear_default_model # }}}
|
73
|
+
|
74
|
+
# @fn def set_default_model_version version # {{{
|
75
|
+
# @brief Set default Model version for usage
|
76
|
+
#
|
77
|
+
# @param [String] - model_name - version of Structure
|
78
|
+
def set_default_model_version version
|
79
|
+
default_model = DefaultModel.first
|
80
|
+
default_model.version = version
|
81
|
+
model = Model.all(:conditions => { :name => default_model.name, :version => version}).first
|
82
|
+
#should save with uuid
|
83
|
+
default_model.uuid = model.uuid
|
84
|
+
default_model.save
|
85
|
+
end # of def set_default_model_version }}}
|
86
|
+
|
87
|
+
# @fn def all_models {{{
|
88
|
+
# @brief Get all Models in database
|
89
|
+
#
|
90
|
+
def all_models
|
91
|
+
Model.all
|
92
|
+
end # of def all_models }}}
|
93
|
+
|
94
|
+
# @fn def check_if_version_available_for_model model, version # {{{
|
95
|
+
# @brief check if model exist with given version
|
96
|
+
#
|
97
|
+
# @param [String] model - model name
|
98
|
+
#
|
99
|
+
# @param [String] version - version number
|
100
|
+
#
|
101
|
+
# @return [Boolean] true, when model exist, otherwise - false
|
102
|
+
def check_if_version_available_for_model model, version
|
103
|
+
model = Model.all(:conditions => { :name => model, :version => version}).first
|
104
|
+
if model.nil?
|
105
|
+
false
|
106
|
+
else
|
107
|
+
true
|
108
|
+
end
|
109
|
+
end # of def check_if_version_available_for_model }}}
|
110
|
+
|
111
|
+
# @fn def default_model_defined? # {{{
|
112
|
+
# @brief check if model name for default is set
|
113
|
+
#
|
114
|
+
# @return [Boolean] true, when defined
|
115
|
+
def default_model_defined?
|
116
|
+
default_model = DefaultModel.first
|
117
|
+
if default_model.nil?
|
118
|
+
false
|
119
|
+
else
|
120
|
+
true
|
121
|
+
end
|
122
|
+
end # of def default_model_defined? # }}}
|
123
|
+
|
124
|
+
end # of Module Database
|
125
|
+
|
126
|
+
end # of module Mixin
|
127
|
+
|
128
|
+
|
129
|
+
# vim:ts=2:tw=100:wm=100:syntax=ruby
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'data_mapper'
|
2
|
+
|
3
|
+
# @class class Model
|
4
|
+
# @brief mapper for Model table, save information about all created Models
|
5
|
+
class DefaultModel
|
6
|
+
include DataMapper::Resource
|
7
|
+
|
8
|
+
property :id, Serial
|
9
|
+
property :name, String
|
10
|
+
property :version, String
|
11
|
+
property :uuid, String
|
12
|
+
end # of class Model
|
13
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# System includes
|
4
|
+
require 'fileutils'
|
5
|
+
require 'tmpdir'
|
6
|
+
|
7
|
+
# Custom include
|
8
|
+
require File.expand_path( File.dirname( __FILE__ ) + '/template_loader' )
|
9
|
+
|
10
|
+
|
11
|
+
module Mixin
|
12
|
+
|
13
|
+
# @module module Generators
|
14
|
+
# @brief Default Namespace for all Generators
|
15
|
+
module Generators
|
16
|
+
|
17
|
+
# @module module BaseGenerator
|
18
|
+
# @brief Contain shared methods which will be used in other Generators
|
19
|
+
module BaseGenerator
|
20
|
+
|
21
|
+
# @fn def load_template language {{{
|
22
|
+
# @brief load template for target language
|
23
|
+
#
|
24
|
+
# @param [String] - target language
|
25
|
+
#
|
26
|
+
# @return [String] - loaded template for target language
|
27
|
+
def load_template language
|
28
|
+
TemplateLoader.load(language)
|
29
|
+
end # def load_template }}}
|
30
|
+
|
31
|
+
end # of module BaseGenerator
|
32
|
+
end # of module Generators
|
33
|
+
end # of module Fox
|
34
|
+
|
35
|
+
# vim:ts=2:tw=100:wm=100:syntax=ruby
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
|
5
|
+
|
6
|
+
module Mixin
|
7
|
+
|
8
|
+
# @module module Generators
|
9
|
+
# @brief Default Namespace for all Generators
|
10
|
+
module Generators
|
11
|
+
|
12
|
+
# @class class Structure
|
13
|
+
# @brief map thrift structure to ruby class
|
14
|
+
class Structure
|
15
|
+
|
16
|
+
# @attribute [w] - structure_name [Symbol] from generated ruby code
|
17
|
+
# @attribute [w] - params [Hash] with types and names of params arguments
|
18
|
+
# @attribute [w] - structure type
|
19
|
+
attr_accessor :structure_name, :params, :type
|
20
|
+
|
21
|
+
# @fn def initialize structure_name, params {{{
|
22
|
+
# @brief Structure constructor
|
23
|
+
#
|
24
|
+
# @param [Symbol] type Type of Structure (class, enum)
|
25
|
+
# @param [String] structure_name Name for structure
|
26
|
+
# @param [Hash] params Fields for user defined structure
|
27
|
+
def initialize type, structure_name, params
|
28
|
+
@type = type
|
29
|
+
if @type == :class
|
30
|
+
raise RuntimeException.new("Params for #{structure_name} empty") if params.size == 0
|
31
|
+
@structure_name, @params = structure_name, params
|
32
|
+
else
|
33
|
+
@structure_name = structure_name
|
34
|
+
end
|
35
|
+
end # def initialize }}}
|
36
|
+
|
37
|
+
end # of class Structure
|
38
|
+
end # of module Generators
|
39
|
+
end # of module Mixin
|
40
|
+
|
41
|
+
# vim:ts=2:tw=100:wm=100:syntax=ruby
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fox/error/errors'
|
4
|
+
|
5
|
+
module Mixin
|
6
|
+
|
7
|
+
# @module module Generators
|
8
|
+
# @brief Default Namespace for all Generators
|
9
|
+
module Generators
|
10
|
+
# @module TemplateLoader
|
11
|
+
# @brief module for load template for target language
|
12
|
+
module TemplateLoader
|
13
|
+
|
14
|
+
extend self
|
15
|
+
|
16
|
+
# default template directory
|
17
|
+
TEMPLATE_DIR = 'template'
|
18
|
+
|
19
|
+
# @fn def load language {{{
|
20
|
+
# @brief Load template for target language
|
21
|
+
#
|
22
|
+
# @param [String] Target language
|
23
|
+
#
|
24
|
+
# @return [String] Result template source
|
25
|
+
def load language
|
26
|
+
file = templates.find { |file| File.basename(file).start_with?(language) }
|
27
|
+
|
28
|
+
raise Fox::LoadTemplateError.new("Template for #{language} not found") if file.nil?
|
29
|
+
|
30
|
+
File.read(file)
|
31
|
+
end
|
32
|
+
|
33
|
+
# of def load }}}
|
34
|
+
|
35
|
+
# @fn def templates {{{
|
36
|
+
# @brief Get list of all templates from `TEMPLATE_DIR`
|
37
|
+
#
|
38
|
+
# @return [Array<String>] List of all templates
|
39
|
+
def templates
|
40
|
+
path = File.expand_path( File.dirname( __FILE__ ) + '../../../../../')
|
41
|
+
Dir["#{path}/#{TEMPLATE_DIR}/*_template.erb"]
|
42
|
+
end # of def templates }}}
|
43
|
+
|
44
|
+
end # of module TemplateLoader
|
45
|
+
end # of module Generators
|
46
|
+
end # of Mixin
|
47
|
+
|
48
|
+
# vim:ts=2:tw=100:wm=100:syntax=ruby
|