Class: MilkTea::ImportedBindings::Binding
- Inherits:
-
Object
- Object
- MilkTea::ImportedBindings::Binding
- Defined in:
- lib/milk_tea/bindings/imported_bindings.rb
Instance Attribute Summary collapse
-
#binding_path ⇒ Object
readonly
Returns the value of attribute binding_path.
-
#import_alias ⇒ Object
readonly
Returns the value of attribute import_alias.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#policy_path ⇒ Object
readonly
Returns the value of attribute policy_path.
-
#raw_module_name ⇒ Object
readonly
Returns the value of attribute raw_module_name.
Instance Method Summary collapse
- #check!(module_roots: [MilkTea.root]) ⇒ Object
- #check_task_name ⇒ Object
- #generate(module_roots: [MilkTea.root]) ⇒ Object
-
#initialize(name:, module_name:, binding_path:, raw_module_name:, policy_path:, import_alias: "c") ⇒ Binding
constructor
A new instance of Binding.
- #task_name ⇒ Object
- #write!(module_roots: [MilkTea.root]) ⇒ Object
Constructor Details
#initialize(name:, module_name:, binding_path:, raw_module_name:, policy_path:, import_alias: "c") ⇒ Binding
Returns a new instance of Binding.
20 21 22 23 24 25 26 27 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 20 def initialize(name:, module_name:, binding_path:, raw_module_name:, policy_path:, import_alias: "c") @name = name.to_s @module_name = module_name @binding_path = File.(binding_path.to_s) @raw_module_name = raw_module_name @policy_path = File.(policy_path.to_s) @import_alias = import_alias end |
Instance Attribute Details
#binding_path ⇒ Object (readonly)
Returns the value of attribute binding_path.
18 19 20 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 18 def binding_path @binding_path end |
#import_alias ⇒ Object (readonly)
Returns the value of attribute import_alias.
18 19 20 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 18 def import_alias @import_alias end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
18 19 20 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 18 def module_name @module_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 18 def name @name end |
#policy_path ⇒ Object (readonly)
Returns the value of attribute policy_path.
18 19 20 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 18 def policy_path @policy_path end |
#raw_module_name ⇒ Object (readonly)
Returns the value of attribute raw_module_name.
18 19 20 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 18 def raw_module_name @raw_module_name end |
Instance Method Details
#check!(module_roots: [MilkTea.root]) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 62 def check!(module_roots: [MilkTea.root]) raw_module_path = resolve_module_path(raw_module_name, module_roots) actual = Generator.new( module_name:, raw_module_name:, raw_module_path:, policy_path:, import_alias:, module_roots:, ).generate expected = File.read(binding_path) if expected != actual raise Error, <<~MESSAGE #{binding_path} is out of date for #{raw_module_path} and #{policy_path} Run `rake #{task_name}` to regenerate it. MESSAGE end MilkTea::ModuleLoader.new(module_roots:).check_file(binding_path) raw_module_path end |
#check_task_name ⇒ Object
33 34 35 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 33 def check_task_name "imported_bindings:check:#{name}" end |
#generate(module_roots: [MilkTea.root]) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 37 def generate(module_roots: [MilkTea.root]) Generator.new( module_name:, raw_module_name:, raw_module_path: resolve_module_path(raw_module_name, module_roots), policy_path:, import_alias:, module_roots:, ).generate end |
#task_name ⇒ Object
29 30 31 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 29 def task_name "imported_bindings:#{name}" end |
#write!(module_roots: [MilkTea.root]) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/milk_tea/bindings/imported_bindings.rb', line 48 def write!(module_roots: [MilkTea.root]) raw_module_path = resolve_module_path(raw_module_name, module_roots) source = Generator.new( module_name:, raw_module_name:, raw_module_path:, policy_path:, import_alias:, module_roots:, ).generate File.write(binding_path, source) raw_module_path end |