dslable 0.0.2 → 0.0.3

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.
@@ -1,24 +1,24 @@
1
- # encoding: utf-8
2
- require 'generators/generators'
3
- require 'fileutils'
4
-
5
- module Dslable::Generators
6
- # Dslable::Generators Gem Template Generator
7
- class GemTemplate
8
- attr_accessor :dsl
9
-
10
- #== initialize generate gem template
11
- #=== Params
12
- #- _dsl: input from dsl
13
- def initialize(_dsl)
14
- @dsl = _dsl
15
- end
16
-
17
- #== generate gem template
18
- def generate
19
- `bundle gem #{@dsl._gem_name}`
20
- Dir.chdir(@dsl._gem_name)
21
- FileUtils.rm_rf("./lib/#{@dsl._gem_name}.rb")
22
- end
23
- end
24
- end
1
+ # encoding: utf-8
2
+ require 'generators/generators'
3
+ require 'fileutils'
4
+
5
+ module Dslable::Generators
6
+ # Dslable::Generators Gem Template Generator
7
+ class GemTemplate
8
+ attr_accessor :dsl
9
+
10
+ # == initialize generate gem template
11
+ # === Params
12
+ #- _dsl: input from dsl
13
+ def initialize(_dsl)
14
+ @dsl = _dsl
15
+ end
16
+
17
+ # == generate gem template
18
+ def generate
19
+ `bundle gem #{@dsl._gem_name}`
20
+ Dir.chdir(@dsl._gem_name)
21
+ FileUtils.rm_rf("./lib/#{@dsl._gem_name}.rb")
22
+ end
23
+ end
24
+ end
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
- require "generators/generators"
3
- require "erb"
2
+ require 'generators/generators'
3
+ require 'erb'
4
4
  require 'active_support/inflector'
5
- require "dslable_dsl"
6
- require "fileutils"
5
+ require 'dslable_dsl'
6
+ require 'fileutils'
7
7
 
8
8
  module Dslable::Generators::ProductCodes
9
9
  class CLI
10
- CLI_TEMPLATE =<<-EOF
10
+ CLI_TEMPLATE = <<-EOF
11
11
  #!/usr/bin/env ruby
12
12
  # encoding: utf-8
13
13
 
@@ -43,11 +43,11 @@ end
43
43
 
44
44
  attr_accessor :dsl
45
45
 
46
- #== initialize dsl model
47
- #=== Params
46
+ # == initialize dsl model
47
+ # === Params
48
48
  #- _dsl: input from dsl
49
49
  def initialize(_dsl)
50
- raise InvalidDslError.new("dsl not allow nil") if _dsl.nil?
50
+ fail InvalidDslError.new('dsl not allow nil') if _dsl.nil?
51
51
  @dsl = _dsl
52
52
  end
53
53
 
@@ -65,10 +65,10 @@ end
65
65
  end
66
66
 
67
67
  def generate_cli_src(cli_src)
68
- FileUtils.mkdir_p("./bin") unless File.exists?("./bin")
69
- File.open("./bin/#{@dsl._bin_name}", "w") {|f|f.puts cli_src}
68
+ FileUtils.mkdir_p('./bin') unless File.exists?('./bin')
69
+ File.open("./bin/#{@dsl._bin_name}", 'w') { |f|f.puts cli_src }
70
70
  end
71
71
  end
72
72
 
73
- class InvalidDslError < StandardError;end
73
+ class InvalidDslError < StandardError; end
74
74
  end
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
- require "dslable_dsl"
3
- require "generators/generators"
4
- require "erb"
2
+ require 'dslable_dsl'
3
+ require 'generators/generators'
4
+ require 'erb'
5
5
  require 'active_support/inflector'
6
6
 
7
7
  module Dslable::Generators::ProductCodes
8
8
  class Core
9
9
  attr_accessor :dsl
10
- CORE_TEMPLATE =<<-END
10
+ CORE_TEMPLATE = <<-END
11
11
  # encoding: utf-8
12
12
  require '<%=gem_name%>_dsl'
13
13
 
@@ -44,11 +44,11 @@ module <%=gem_name_camel%>
44
44
  end
45
45
  END
46
46
 
47
- #== initialize core
48
- #=== Params
47
+ # == initialize core
48
+ # === Params
49
49
  #- _dsl: input from dsl
50
50
  def initialize(_dsl)
51
- raise InvalidDslError.new("dls not allow nil") if _dsl.nil?
51
+ fail InvalidDslError.new('dls not allow nil') if _dsl.nil?
52
52
  @dsl = _dsl
53
53
  end
54
54
 
@@ -72,7 +72,7 @@ end
72
72
  field_dsls << get_field_klass(field)
73
73
  field_dsls << get_field_default(field) unless field._args._default_value.nil?
74
74
  field_dsls << get_field_call(field)
75
- field_dsls << [""]
75
+ field_dsls << ['']
76
76
  field_dsls_all << field_dsls.join("\n")
77
77
  end
78
78
  field_dsls_all.join("\n")
@@ -113,11 +113,15 @@ end
113
113
  end
114
114
 
115
115
  def nil_default_array
116
- ["your value"]
116
+ ['your value']
117
117
  end
118
118
 
119
119
  def nil_default_hash
120
- {"your key" => "your value"}
120
+ { 'your key' => 'your value' }
121
+ end
122
+
123
+ def nil_default_boolean
124
+ false
121
125
  end
122
126
 
123
127
  def adapt_template(gem_name_camel, gem_name_upper, dsl_file_name, fields, gem_name)
@@ -126,9 +130,9 @@ end
126
130
  end
127
131
 
128
132
  def generate_core_src(core_src)
129
- File.open("./lib/#{@dsl._gem_name}_core.rb", "w") {|f|f.puts core_src}
133
+ File.open("./lib/#{@dsl._gem_name}_core.rb", 'w') { |f|f.puts core_src }
130
134
  end
131
135
  end
132
136
 
133
- class InvalidDslError < StandardError;end
137
+ class InvalidDslError < StandardError; end
134
138
  end
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
- require "generators/generators"
3
- require "erb"
2
+ require 'generators/generators'
3
+ require 'erb'
4
4
  require 'active_support/inflector'
5
- require "dslable_dsl"
5
+ require 'dslable_dsl'
6
6
 
7
7
  module Dslable::Generators::ProductCodes
8
8
  class Dsl
9
- DSL_TEMPLATE =<<-EOF
9
+ DSL_TEMPLATE = <<-EOF
10
10
  # encoding: utf-8
11
11
  require '<%=gem_name%>_dsl_model'
12
12
 
@@ -21,7 +21,7 @@ module <%=gem_name_camel%>
21
21
  end
22
22
  end
23
23
 
24
- # Array/Hash Define
24
+ # Array/Hash/Boolean Define
25
25
  [<%=array_hash_fields%>].each do |f|
26
26
  define_method f do |value|
27
27
  eval "@<%=gem_name%>.#\{f.to_s} = #\{value}", binding
@@ -38,16 +38,16 @@ end
38
38
 
39
39
  attr_accessor :dsl
40
40
 
41
- #== initialize dsl
42
- #=== Params
41
+ # == initialize dsl
42
+ # === Params
43
43
  #- _dsl: input from dsl
44
44
  def initialize(_dsl)
45
- raise InvalidDslError.new("dsl not allow nil") if _dsl.nil?
45
+ fail InvalidDslError.new('dsl not allow nil') if _dsl.nil?
46
46
  @dsl = _dsl
47
47
  end
48
48
 
49
49
  def generate
50
- dsl_src = adapt_template(@dsl.camelized_gem_name, get_string_fields, get_array_hash_fields, get_set_defaults)
50
+ dsl_src = adapt_template(@dsl.camelized_gem_name, get_string_fields, get_other_fields, get_set_defaults)
51
51
  generate_dsl_src dsl_src
52
52
  end
53
53
 
@@ -57,15 +57,15 @@ end
57
57
  @dsl.fields.each do |field|
58
58
  fields << ":#{field._field_name}" if field._args._klass == String
59
59
  end
60
- fields.join(", ")
60
+ fields.join(', ')
61
61
  end
62
62
 
63
- def get_array_hash_fields
63
+ def get_other_fields
64
64
  fields = []
65
65
  @dsl.fields.each do |field|
66
66
  fields << ":#{field._field_name}" unless field._args._klass == String
67
67
  end
68
- fields.join(", ")
68
+ fields.join(', ')
69
69
  end
70
70
 
71
71
  def get_set_defaults
@@ -86,9 +86,9 @@ end
86
86
  end
87
87
 
88
88
  def generate_dsl_src(dsl_src)
89
- File.open("./lib/#{@dsl._gem_name}_dsl.rb", "w") {|f|f.puts dsl_src}
89
+ File.open("./lib/#{@dsl._gem_name}_dsl.rb", 'w') { |f|f.puts dsl_src }
90
90
  end
91
91
  end
92
92
 
93
- class InvalidDslError < StandardError;end
93
+ class InvalidDslError < StandardError; end
94
94
  end
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
- require "generators/generators"
3
- require "erb"
2
+ require 'generators/generators'
3
+ require 'erb'
4
4
  require 'active_support/inflector'
5
- require "dslable_dsl"
5
+ require 'dslable_dsl'
6
6
 
7
7
  module Dslable::Generators::ProductCodes
8
8
  class DslModel
9
- DSL_MODEL_TEMPLATE =<<-EOF
9
+ DSL_MODEL_TEMPLATE = <<-EOF
10
10
  # encoding: utf-8
11
11
  require 'active_model'
12
12
 
@@ -21,11 +21,11 @@ end
21
21
 
22
22
  attr_accessor :dsl
23
23
 
24
- #== initialize dsl model
25
- #=== Params
24
+ # == initialize dsl model
25
+ # === Params
26
26
  #- _dsl: input from dsl
27
27
  def initialize(_dsl)
28
- raise InvalidDslError.new("dsl not allow nil") if _dsl.nil?
28
+ fail InvalidDslError.new('dsl not allow nil') if _dsl.nil?
29
29
  @dsl = _dsl
30
30
  end
31
31
 
@@ -42,7 +42,7 @@ end
42
42
  field_codes << " # #{field._desc}"
43
43
  field_codes << " attr_accessor :#{field._field_name}"
44
44
  field_codes << " validates :#{field._field_name}, :presence => true" if field._args._required
45
- field_codes << ""
45
+ field_codes << ''
46
46
  fields << field_codes.join("\n")
47
47
  end
48
48
  fields.join("\n")
@@ -55,9 +55,9 @@ end
55
55
  end
56
56
 
57
57
  def generate_dsl_model_src(dsl_model_src)
58
- File.open("./lib/#{@dsl._gem_name}_dsl_model.rb", "w") {|f|f.puts dsl_model_src}
58
+ File.open("./lib/#{@dsl._gem_name}_dsl_model.rb", 'w') { |f|f.puts dsl_model_src }
59
59
  end
60
60
  end
61
61
 
62
- class InvalidDslError < StandardError;end
62
+ class InvalidDslError < StandardError; end
63
63
  end
@@ -1,21 +1,21 @@
1
- # encoding: utf-8
2
- require "generators/generators"
3
-
4
- module Dslable::Generators::RSpec
5
- # Dslable::Generators::RSpec RSpec Template Generator(only execute 'rspec --init')
6
- class SpecTemplate
7
- attr_accessor :dsl
8
-
9
- #== initialize generate rspec template
10
- #=== Params
11
- #- _dsl: input from dsl
12
- def initialize(_dsl)
13
- @dsl = _dsl
14
- end
15
-
16
- #== generate rspec template
17
- def generate
18
- `rspec --init`
19
- end
20
- end
21
- end
1
+ # encoding: utf-8
2
+ require 'generators/generators'
3
+
4
+ module Dslable::Generators::RSpec
5
+ # Dslable::Generators::RSpec RSpec Template Generator(only execute 'rspec --init')
6
+ class SpecTemplate
7
+ attr_accessor :dsl
8
+
9
+ # == initialize generate rspec template
10
+ # === Params
11
+ #- _dsl: input from dsl
12
+ def initialize(_dsl)
13
+ @dsl = _dsl
14
+ end
15
+
16
+ # == generate rspec template
17
+ def generate
18
+ `rspec --init`
19
+ end
20
+ end
21
+ end
@@ -1,27 +1,27 @@
1
- # encoding: utf-8
2
- require "generators/generators"
3
-
4
- module Dslable::Generators::RSpec
5
- # Dslable::Generators::RSpec Specs Generator specs
6
- class Specs
7
- attr_accessor :dsl
8
-
9
- #== initialize generate specs
10
- #=== Params
11
- #- _dsl: input from dsl
12
- def initialize(_dsl)
13
- @dsl = _dsl
14
- end
15
-
16
- #== generate specs
17
- def generate
18
- generate_core
19
- end
20
-
21
- def generate_core
22
- core_class_name = "#{@dsl.camelized_gem_name}::Core"
23
- core_class_file_name = "#{@dsl._gem_name}_core"
24
- `piccolo e #{core_class_name} #{core_class_file_name} init execute`
25
- end
26
- end
27
- end
1
+ # encoding: utf-8
2
+ require 'generators/generators'
3
+
4
+ module Dslable::Generators::RSpec
5
+ # Dslable::Generators::RSpec Specs Generator specs
6
+ class Specs
7
+ attr_accessor :dsl
8
+
9
+ # == initialize generate specs
10
+ # === Params
11
+ #- _dsl: input from dsl
12
+ def initialize(_dsl)
13
+ @dsl = _dsl
14
+ end
15
+
16
+ # == generate specs
17
+ def generate
18
+ generate_core
19
+ end
20
+
21
+ def generate_core
22
+ core_class_name = "#{@dsl.camelized_gem_name}::Core"
23
+ core_class_file_name = "#{@dsl._gem_name}_core"
24
+ `piccolo e #{core_class_name} #{core_class_file_name} init execute`
25
+ end
26
+ end
27
+ end
@@ -1,10 +1,10 @@
1
1
  # encoding: utf-8
2
- require "generators/generators"
3
- require "dslable_dsl"
2
+ require 'generators/generators'
3
+ require 'dslable_dsl'
4
4
 
5
5
  module Dslable::Generators::Settings
6
6
  class Gemfile
7
- GEMFILE_TEMPLATE =<<-EOF
7
+ GEMFILE_TEMPLATE = <<-EOF
8
8
  source 'https://rubygems.org'
9
9
 
10
10
  gemspec
@@ -18,17 +18,17 @@ gem "tudu", "~> 0.0.4"
18
18
 
19
19
  attr_accessor :dsl
20
20
 
21
- #== initialize dsl model
22
- #=== Params
21
+ # == initialize dsl model
22
+ # === Params
23
23
  #- _dsl: input from dsl
24
24
  def initialize(_dsl)
25
- raise InvalidDslError.new("dsl not allow nil") if _dsl.nil?
25
+ fail InvalidDslError.new('dsl not allow nil') if _dsl.nil?
26
26
  @dsl = _dsl
27
27
  end
28
28
 
29
29
  def generate
30
- File.open("./Gemfile", "w") {|f|f.puts GEMFILE_TEMPLATE}
30
+ File.open('./Gemfile', 'w') { |f|f.puts GEMFILE_TEMPLATE }
31
31
  end
32
32
  end
33
- class InvalidDslError < StandardError;end
33
+ class InvalidDslError < StandardError; end
34
34
  end
@@ -1,76 +1,76 @@
1
- # encoding: utf-8
2
- require 'generators/generators'
3
- require 'fileutils'
4
- require 'dslable_dsl'
5
- require 'erb'
6
-
7
- module Dslable::Generators
8
- # =Dslable::Generators Gem Template Generator
9
- class Workflow
10
- # ==todos contents
11
- TODOS_CONTENTS = <<-EOS
12
- implement '<%=gem_name%>_core.rb' your main logic. pass rspec all specs.
13
- implement bin 'bin/<%=bin_name%>'.
14
- edit '<%=gem_name%>.gemspec'.
15
- edit 'README.md'.
16
- edit 'LICENSE.txt'.
17
- git add, commit.
18
- rake install.
19
- check gem(test using).
20
- gem uninstall <%=gem_name%>.
21
- rake release.
22
- gem install <%=gem_name%>.
23
- after release check.
24
- EOS
25
-
26
- # ==doings contents
27
- DOINGS_CONTENTS = <<-EOS
28
- implement '<%=gem_name%>_core_spec.rb'.
29
- EOS
30
-
31
- # ==tudu file definitions
32
- TUDU_FILES = {
33
- :todos => {
34
- :file_name => 'tudu/todos',
35
- :contents => TODOS_CONTENTS
36
- },
37
- :doings => {
38
- :file_name => 'tudu/doings',
39
- :contents => DOINGS_CONTENTS
40
- },
41
- :dones => {
42
- :file_name => 'tudu/dones',
43
- :contents => ''
44
- },
45
- }
46
- attr_accessor :dsl
47
-
48
- #== initialize generate gem template
49
- #=== Params
50
- #- _dsl: input from dsl
51
- def initialize(_dsl)
52
- raise InvalidDslError.new('dsl not allow nil') if _dsl.nil?
53
- @dsl = _dsl
54
- end
55
-
56
- #== generate gem template
57
- def generate
58
- Dir.mkdir('tudu')
59
- gem_name = @dsl._gem_name
60
- bin_name = @dsl._bin_name
61
- TUDU_FILES.each do |key, file_definition|
62
- File.open("./#{file_definition[:file_name]}", "w") do |f|
63
- f.print adapt_template(gem_name, bin_name, file_definition[:contents])
64
- end
65
- end
66
- end
67
-
68
- private
69
-
70
- def adapt_template(gem_name, bin_name, template)
71
- erb = ERB.new(template)
72
- erb.result(binding)
73
- end
74
- end
75
- class InvalidDslError < StandardError;end
76
- end
1
+ # encoding: utf-8
2
+ require 'generators/generators'
3
+ require 'fileutils'
4
+ require 'dslable_dsl'
5
+ require 'erb'
6
+
7
+ module Dslable::Generators
8
+ # =Dslable::Generators Gem Template Generator
9
+ class Workflow
10
+ # ==todos contents
11
+ TODOS_CONTENTS = <<-EOS
12
+ implement '<%=gem_name%>_core.rb' your main logic. pass rspec all specs.
13
+ implement bin 'bin/<%=bin_name%>'.
14
+ edit '<%=gem_name%>.gemspec'.
15
+ edit 'README.md'.
16
+ edit 'LICENSE.txt'.
17
+ git add, commit.
18
+ rake install.
19
+ check gem(test using).
20
+ gem uninstall <%=gem_name%>.
21
+ rake release.
22
+ gem install <%=gem_name%>.
23
+ after release check.
24
+ EOS
25
+
26
+ # ==doings contents
27
+ DOINGS_CONTENTS = <<-EOS
28
+ implement '<%=gem_name%>_core_spec.rb'.
29
+ EOS
30
+
31
+ # ==tudu file definitions
32
+ TUDU_FILES = {
33
+ todos: {
34
+ file_name: 'tudu/todos',
35
+ contents: TODOS_CONTENTS
36
+ },
37
+ doings: {
38
+ file_name: 'tudu/doings',
39
+ contents: DOINGS_CONTENTS
40
+ },
41
+ dones: {
42
+ file_name: 'tudu/dones',
43
+ contents: ''
44
+ },
45
+ }
46
+ attr_accessor :dsl
47
+
48
+ # == initialize generate gem template
49
+ # === Params
50
+ #- _dsl: input from dsl
51
+ def initialize(_dsl)
52
+ fail InvalidDslError.new('dsl not allow nil') if _dsl.nil?
53
+ @dsl = _dsl
54
+ end
55
+
56
+ # == generate gem template
57
+ def generate
58
+ Dir.mkdir('tudu')
59
+ gem_name = @dsl._gem_name
60
+ bin_name = @dsl._bin_name
61
+ TUDU_FILES.each do |key, file_definition|
62
+ File.open("./#{file_definition[:file_name]}", 'w') do |f|
63
+ f.print adapt_template(gem_name, bin_name, file_definition[:contents])
64
+ end
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def adapt_template(gem_name, bin_name, template)
71
+ erb = ERB.new(template)
72
+ erb.result(binding)
73
+ end
74
+ end
75
+ class InvalidDslError < StandardError; end
76
+ end