modables_dsl 0.1.0 → 0.1.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: d67000220f3da24d94fc9cbcc9b5f14425889a3e
4
- data.tar.gz: 802610e8538ed73ca3f68c119c73e5aa03675f62
3
+ metadata.gz: c8389a2bcc2c1e7ce17100ba4ac0f70d8b163255
4
+ data.tar.gz: dadfcf9c8e3a8173ee21f47698d9347b59b2e7fc
5
5
  SHA512:
6
- metadata.gz: 5519b59da421099d59b9af39e58d1c71c66ee409deee7c315ac6a9a071d78bc3e927c003c2c3ad5c07a9138edb3f5eafbf4f9b10a5d19358ff628dc9e0012b86
7
- data.tar.gz: 29524d2c10ceba5f7fc6e961d8584def67f3d2ddd9ee193f7dd1085c9aeabff9fde337822cb898a1d5dd54053a7696fc42ed1b024484457c7bcc7fc5e5259912
6
+ metadata.gz: 948efd2084ce5f75044db45c2e120b1ccb8566a6cad41879093c1c8fcf3bc7d503250fca0258aacc7906e7df12b218b315d022e0f89201448abfa01c7759d0e9
7
+ data.tar.gz: c713d72d8da299c3182810e0e87a74dde7ddc7c5bfc44a85773729313db0fe56c642d305818116676a509ac162da11b6ee265afa54ffb9b0c010cff70255ed01
data/lib/modables_dsl.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support/json'
2
2
  require 'active_support/core_ext/hash/deep_merge'
3
+ require 'active_support/core_ext/string/inflections'
3
4
  require 'logger'
4
5
  require 'optparse'
5
6
  require 'yaml'
@@ -10,3 +11,4 @@ require 'modables_dsl/dsl/arguments'
10
11
  require 'modables_dsl/dsl/core'
11
12
  require 'modables_dsl/generate'
12
13
  require 'modables_dsl/message'
14
+ require 'modables_dsl/version'
@@ -2,21 +2,32 @@ module ModablesDSL
2
2
  module Cli
3
3
 
4
4
  def self.parse
5
- OptionParser.new do|args|
5
+ option_parser = OptionParser.new do|args|
6
6
  args.banner = "Usage: modables-dsl [options]"
7
- args.on('-c', '--config config', 'YAML config file') do |config|
7
+ args.on('-c', '--config file.yaml', 'YAML config file') do |config|
8
8
  self.opts['config'] = config
9
9
  end
10
10
 
11
- args.on('-d', '--dir', 'Use directory list from config') do |dir|
12
- self.opts['dir'] = dir
11
+ args.on('-f', '--file-ext tf.json', 'JSON output file extension') do |file_ext|
12
+ self.opts['file-ext'] = file_ext
13
+ end
14
+
15
+ args.on('-v', '--version', 'DSL version') do |version|
16
+ puts ModablesDSL::VERSION
17
+ exit 0
13
18
  end
14
19
 
15
20
  args.on('-h', '--help', 'Show this message') do
16
21
  puts args
17
22
  exit 0
18
23
  end
19
- end.parse!
24
+ end
25
+
26
+ begin
27
+ option_parser.parse!
28
+ rescue OptionParser::MissingArgument => e
29
+ ModablesDSL::Message.error "#{e.message}"
30
+ end
20
31
 
21
32
  ModablesDSL::Generate.files
22
33
  end
@@ -3,13 +3,26 @@ module ModablesDSL
3
3
 
4
4
  def self.get
5
5
  if @config.nil?
6
+
7
+ @config = {
8
+ 'dsl' => {
9
+ 'file_ext' => 'moda.json',
10
+ 'stack_dirs' => Array.new,
11
+ }
12
+ }
13
+
6
14
  config_file = ModablesDSL::Cli.opts['config'] || "#{ENV['HOME']}/.modables.yaml"
7
15
 
8
- unless File.file? config_file
9
- ModablesDSL::Message.error "Config file does not exist. (#{config_file})"
10
- end
16
+ # try to read from config file
17
+ if File.file? config_file
18
+ ModablesDSL::Message.log.info "Loading config #{config_file}"
19
+ @config.deep_merge!(YAML.load_file(config_file))
11
20
 
12
- @config = YAML.load_file(config_file)
21
+ # if config file arg is passed but file is missing
22
+ elsif ModablesDSL::Cli.opts['config']
23
+ ModablesDSL::Message.error "Config file #{config_file} not found"
24
+ exit 1
25
+ end
13
26
  end
14
27
 
15
28
  @config
@@ -9,6 +9,9 @@ module ModablesDSL
9
9
 
10
10
  def property meth, *args, &block
11
11
 
12
+ # If requested convert underscrores to dashes.
13
+ meth = ActiveSupport::Inflector.dasherize(meth.to_s) if args.include? :dash
14
+
12
15
  # If a block is passed it means we are building a hash.
13
16
  if block
14
17
 
@@ -33,11 +36,7 @@ module ModablesDSL
33
36
 
34
37
  # Else its a String, Integer, Boolean or Array.
35
38
  else
36
- if args.include? :json
37
- @args_h[meth] = ActiveSupport::JSON.encode(args.last)
38
- else
39
- @args_h[meth] = args.last
40
- end
39
+ @args_h[meth] = args.last
41
40
  end
42
41
 
43
42
  end
@@ -26,7 +26,7 @@ module ModablesDSL
26
26
  ActiveSupport::JSON.encode(@data)
27
27
  end
28
28
 
29
- def self.gen
29
+ def self.moda
30
30
  yield
31
31
  self.encode_json
32
32
  end
@@ -2,17 +2,17 @@ module ModablesDSL
2
2
  module Generate
3
3
 
4
4
  def self.files
5
- self.stack_files.each do |mod_file|
5
+ self.stack_files.each do |moda_file|
6
6
 
7
- file_prefix = mod_file.rpartition('.mod').first
8
- file_suffix = ModablesDSL::Config.get['dsl']['destination_file_suffix'] || 'mod.json'
7
+ file_prefix = moda_file.rpartition('.moda').first
8
+ file_suffix = ModablesDSL::Cli.opts['file-ext'] || ModablesDSL::Config.get['dsl']['file_ext']
9
9
 
10
10
  destination_file = "#{file_prefix}.#{file_suffix}"
11
11
 
12
- ModablesDSL::Message.log.info "Reading from #{mod_file}"
12
+ ModablesDSL::Message.log.info "Reading from #{moda_file}"
13
13
 
14
14
  File.open(destination_file, 'w') do |new_file|
15
- new_file.write ModablesDSL::DSL.instance_eval IO.read mod_file
15
+ new_file.write ModablesDSL::DSL.instance_eval IO.read moda_file
16
16
  end
17
17
 
18
18
  ModablesDSL::Message.log.info "Wrote to #{destination_file}"
@@ -21,19 +21,23 @@ module ModablesDSL
21
21
 
22
22
  def self.stack_files
23
23
 
24
- dirs = if ModablesDSL::Cli.opts['dir']
25
- ModablesDSL::Config.get['dsl']['stack_dirs']
26
- else
27
- [Dir.pwd]
24
+ moda_files = Array.new
25
+ stack_dirs = ModablesDSL::Config.get['dsl']['stack_dirs'] << Dir.pwd
26
+
27
+ stack_dirs.each do |dir|
28
+ moda_files += Dir.glob("#{dir}/**/*.moda")
28
29
  end
29
30
 
30
- mod_files = Array.new
31
+ total_moda_files = moda_files.size
31
32
 
32
- dirs.each do |dir|
33
- mod_files += Dir.glob("#{dir}/**/*.mod.rb")
33
+ if total_moda_files == 0
34
+ ModablesDSL::Message.log.info '0 moda files found.'
35
+ exit 0
36
+ else
37
+ ModablesDSL::Message.log.info "#{total_moda_files} moda #{"file".pluralize(total_moda_files)} found"
34
38
  end
35
39
 
36
- mod_files
40
+ moda_files
37
41
  end
38
42
 
39
43
  end
@@ -1,3 +1,3 @@
1
1
  module ModablesDSL
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modables_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Modables
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport