Class: Dslable::Generators::ProductCodes::Core
- Inherits:
-
Object
- Object
- Dslable::Generators::ProductCodes::Core
- Defined in:
- lib/generators/product_codes/core.rb
Constant Summary collapse
- CORE_TEMPLATE =
<<-END # encoding: utf-8 require '<%=gem_name%>_dsl' module <%=gem_name_camel%> # <%=gem_name_camel%> Core class Core <%=gem_name_upper%>_FILE = "<%=dsl_file_name%>" <%=gem_name_upper%>_TEMPLATE =<<-EOS # encoding: utf-8 <%=fields%> EOS #== generate <%=dsl_file_name%> to current directory. def init File.open(<%=gem_name_upper%>_FILE, "w") {|f|f.puts <%=gem_name_upper%>_TEMPLATE} end #== TODO: write your gem's specific contents def execute src = read_dsl dsl = <%=gem_name_camel%>::Dsl.new dsl.instance_eval src # TODO: implement your gem's specific logic end private def read_dsl File.open(<%=gem_name_upper%>_FILE) {|f|f.read} end end end END
Instance Attribute Summary collapse
-
#dsl ⇒ Object
Returns the value of attribute dsl.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(_dsl) ⇒ Core
constructor
initialize core === Params - _dsl: input from dsl.
Constructor Details
#initialize(_dsl) ⇒ Core
initialize core
Params
-
_dsl: input from dsl
50 51 52 53 |
# File 'lib/generators/product_codes/core.rb', line 50 def initialize(_dsl) fail InvalidDslError.new('dls not allow nil') if _dsl.nil? @dsl = _dsl end |
Instance Attribute Details
#dsl ⇒ Object
Returns the value of attribute dsl.
9 10 11 |
# File 'lib/generators/product_codes/core.rb', line 9 def dsl @dsl end |
Instance Method Details
#generate ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/product_codes/core.rb', line 55 def generate gem_name_camel = @dsl.camelized_gem_name gem_name_upper = @dsl._gem_name.upcase dsl_file_name = "#{@dsl._gem_name.camelize.downcase.camelize}file" fields = get_fields core_src = adapt_template(gem_name_camel, gem_name_upper, dsl_file_name, fields, @dsl._gem_name) generate_core_src core_src end |