Module: GoonModelGen::Templates::DSL
- Included in:
- Generator
- Defined in:
- lib/goon_model_gen/templates/dsl.rb
Constant Summary collapse
- PARTITION_PATTERNS =
[ /\A[^\.\/]+(?:\/.+)?\z/, /\Agopkg\.in\//, /\Agolang\.org\//, /\Agoogle\.golang\.org\//, /\Agithub\.com\//, ].freeze
Instance Method Summary collapse
- #dependencies ⇒ Object
- #import(alias_or_package, package_or_nil = nil) ⇒ Object
- #partition(paths) ⇒ Object
- #partitioned_imports(except: []) ⇒ Object
- #user_editable(value: true) ⇒ Object
- #user_editable? ⇒ Boolean
Instance Method Details
#dependencies ⇒ Object
8 9 10 |
# File 'lib/goon_model_gen/templates/dsl.rb', line 8 def dependencies @dependencies ||= {} end |
#import(alias_or_package, package_or_nil = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/goon_model_gen/templates/dsl.rb', line 12 def import(alias_or_package, package_or_nil = nil) package_path = package_or_nil || alias_or_package new_alias = package_or_nil ? alias_or_package.to_s : nil package_path = package_path.path if package_path.respond_to?(:path) package_path = package_alias_map[package_path] return if package_path.blank? if dependencies.key?(package_path) old_alias = dependencies[package_path] raise "Conflict alias #{old_alias.inspect} and #{new_alias.inspect}" if old_alias != new_alias end dependencies[package_path] ||= new_alias end |
#partition(paths) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/goon_model_gen/templates/dsl.rb', line 44 def partition(paths) groups = paths.group_by do |path| PARTITION_PATTERNS.index{|ptn| ptn =~ path} || PARTITION_PATTERNS.length end groups.keys.sort.map{|k| groups[k].sort } end |
#partitioned_imports(except: []) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/goon_model_gen/templates/dsl.rb', line 25 def partitioned_imports(except: []) pkg_paths = dependencies.keys - except import_contents = partition(pkg_paths).map do |group| group.map do |path| ailas_name = dependencies[path] ailas_name ? "\t#{ailas_name} \"#{path}\"" : "\t\"#{path}\"" end.join("\n") end import_contents.empty? ? '' : "import (\n%s\n)\n" % import_contents.join("\n\n") end |
#user_editable(value: true) ⇒ Object
51 52 53 |
# File 'lib/goon_model_gen/templates/dsl.rb', line 51 def user_editable(value: true) @user_editable = value end |
#user_editable? ⇒ Boolean
55 56 57 |
# File 'lib/goon_model_gen/templates/dsl.rb', line 55 def user_editable? @user_editable end |